|
@@ -15,12 +15,18 @@ func TestFlow(t *testing.T) {
|
|
|
if got, want := f.cur(), int32(10); got != want {
|
|
if got, want := f.cur(), int32(10); got != want {
|
|
|
t.Fatalf("size = %d; want %d", got, want)
|
|
t.Fatalf("size = %d; want %d", got, want)
|
|
|
}
|
|
}
|
|
|
- if waits := f.acquire(1); waits != 0 {
|
|
|
|
|
- t.Errorf("waits = %d; want 0", waits)
|
|
|
|
|
|
|
+ if got, want := f.wait(1), int32(1); got != want {
|
|
|
|
|
+ t.Errorf("wait = %d; want %d", got, want)
|
|
|
}
|
|
}
|
|
|
if got, want := f.cur(), int32(9); got != want {
|
|
if got, want := f.cur(), int32(9); got != want {
|
|
|
t.Fatalf("size = %d; want %d", got, want)
|
|
t.Fatalf("size = %d; want %d", got, want)
|
|
|
}
|
|
}
|
|
|
|
|
+ if got, want := f.wait(20), int32(9); got != want {
|
|
|
|
|
+ t.Errorf("wait = %d; want %d", got, want)
|
|
|
|
|
+ }
|
|
|
|
|
+ if got, want := f.cur(), int32(0); got != want {
|
|
|
|
|
+ t.Fatalf("size = %d; want %d", got, want)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// Wait for 10, which should block, so start a background goroutine
|
|
// Wait for 10, which should block, so start a background goroutine
|
|
|
// to refill it.
|
|
// to refill it.
|
|
@@ -28,8 +34,8 @@ func TestFlow(t *testing.T) {
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
f.add(50)
|
|
f.add(50)
|
|
|
}()
|
|
}()
|
|
|
- if waits := f.acquire(10); waits != 1 {
|
|
|
|
|
- t.Errorf("waits for 50 = %d; want 0", waits)
|
|
|
|
|
|
|
+ if got, want := f.wait(1), int32(1); got != want {
|
|
|
|
|
+ t.Errorf("after block, got %d; want %d", got, want)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if got, want := f.cur(), int32(49); got != want {
|
|
if got, want := f.cur(), int32(49); got != want {
|
|
@@ -69,13 +75,15 @@ func TestFlowClose(t *testing.T) {
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
f.close()
|
|
f.close()
|
|
|
}()
|
|
}()
|
|
|
- donec := make(chan bool)
|
|
|
|
|
|
|
+ gotc := make(chan int32)
|
|
|
go func() {
|
|
go func() {
|
|
|
- defer close(donec)
|
|
|
|
|
- f.acquire(10)
|
|
|
|
|
|
|
+ gotc <- f.wait(1)
|
|
|
}()
|
|
}()
|
|
|
select {
|
|
select {
|
|
|
- case <-donec:
|
|
|
|
|
|
|
+ case got := <-gotc:
|
|
|
|
|
+ if got != 0 {
|
|
|
|
|
+ t.Errorf("got %d; want 0", got)
|
|
|
|
|
+ }
|
|
|
case <-time.After(2 * time.Second):
|
|
case <-time.After(2 * time.Second):
|
|
|
t.Error("timeout")
|
|
t.Error("timeout")
|
|
|
}
|
|
}
|