queue: detect close of incoming channel

This commit is contained in:
Joost Jager
2020-04-06 14:47:49 +02:00
parent 278915e598
commit f907fbcadc
2 changed files with 47 additions and 2 deletions

View File

@@ -63,3 +63,25 @@ func TestConcurrentQueueIdempotentStop(t *testing.T) {
testQueueAddDrain(t, 100, 1, 10, 1000, 1000)
}
// TestQueueCloseIncoming tests that the queue properly handles an incoming
// channel that is closed.
func TestQueueCloseIncoming(t *testing.T) {
t.Parallel()
queue := queue.NewConcurrentQueue(10)
queue.Start()
queue.ChanIn() <- 1
close(queue.ChanIn())
item := <-queue.ChanOut()
if item.(int) != 1 {
t.Fatalf("unexpected item")
}
_, ok := <-queue.ChanOut()
if ok {
t.Fatalf("expected outgoing channel being closed")
}
}