@@ -358,6 +358,48 @@ func TestBlockingSelectAsyncSend(t *testing.T) {
358358 require .EqualValues (t , expected , history )
359359}
360360
361+ func TestSelectOnClosedChannel (t * testing.T ) {
362+ var history []string
363+ d , _ := newDispatcher (createRootTestContext (), func (ctx Context ) {
364+ c := NewBufferedChannel (ctx , 1 )
365+ c .Send (ctx , 5 )
366+ c .Close ()
367+
368+ selector := NewNamedSelector (ctx , "waiting for channel" )
369+
370+ selector .AddReceive (c , func (f Channel , more bool ) {
371+ var n int
372+
373+ if ! more {
374+ history = append (history , "more from function is false" )
375+ return
376+ }
377+
378+ more = f .Receive (ctx , & n )
379+ if ! more {
380+ history = append (history , "more from receive is false" )
381+ return
382+ }
383+ history = append (history , fmt .Sprintf ("got message on channel: %v" , n ))
384+ })
385+
386+ selector .Select (ctx )
387+ selector .Select (ctx )
388+ selector .Select (ctx )
389+ selector .Select (ctx )
390+ })
391+ d .ExecuteUntilAllBlocked ()
392+ require .True (t , d .IsDone (), strings .Join (history , "\n " ))
393+
394+ expected := []string {
395+ "got message on channel: 5" ,
396+ "more from function is false" ,
397+ "more from function is false" ,
398+ "more from function is false" ,
399+ }
400+ require .EqualValues (t , expected , history )
401+ }
402+
361403func TestBlockingSelectAsyncSend2 (t * testing.T ) {
362404 var history []string
363405 d , _ := newDispatcher (createRootTestContext (), func (ctx Context ) {
0 commit comments