@@ -32,17 +32,17 @@ func TestQueueCtx(t *testing.T) {
3232 assert .Equal (t , q .Size (), 0 )
3333}
3434
35- func TestQueueClose (t * testing.T ) {
35+ func TestQueueStop (t * testing.T ) {
3636 q := NewQueue [int ]()
3737 q .Put (12 )
3838 q .Put (13 )
39- q .Close ()
39+ q .Stop ()
4040 q .Put (16 )
41- assert .Assert (t , q .Closed ())
41+ assert .Assert (t , q .Stopped ())
4242 expected := []int {12 , 13 }
43- items , err := readNWithTimeout (q , 3 )
44- assert .ErrorIs (t , err , ErrClosed )
45- assert .DeepEqual (t , expected , items )
43+ items , err := readNWithTimeout (q , 3 ) // can still Get after Stop.
44+ assert .ErrorIs (t , err , ErrStopped )
45+ assert .DeepEqual (t , expected , items ) // still gets the expected items.
4646}
4747
4848func TestQueueTimeout (t * testing.T ) {
@@ -55,6 +55,19 @@ func TestQueueTimeout(t *testing.T) {
5555 assert .DeepEqual (t , expected , items )
5656}
5757
58+ func TestQueueClose (t * testing.T ) {
59+ q := NewQueue [int ]()
60+ q .Put (12 )
61+ q .Put (13 )
62+ q .Close ()
63+ q .Put (16 )
64+ assert .Assert (t , q .Stopped ())
65+ var expected []int // Close drains all pending items.
66+ items , err := readNWithTimeout (q , 2 ) // can still get after close
67+ assert .ErrorIs (t , err , ErrStopped )
68+ assert .DeepEqual (t , expected , items )
69+ }
70+
5871func TestQueueCtxTimeout (t * testing.T ) {
5972 ctx := context .Background ()
6073 q := NewQueue [int ]()
@@ -98,8 +111,9 @@ func TestQueueConcurrency(t *testing.T) {
98111 }()
99112 }
100113 wgPut .Wait ()
101- q .Close ()
114+ q .Stop ()
102115 wgGet .Wait ()
116+ q .Close ()
103117
104118 assert .Assert (t , cmp2 .Len (putItems , 10 * 10 ))
105119 assert .Assert (t , cmp2 .Len (getItems , 10 * 10 ))
@@ -147,7 +161,7 @@ func readNWithTimeout[E any, Q ListType[E]](q *List[E, Q], n int) ([]E, error) {
147161 select {
148162 case item , ok := <- q .Get ():
149163 if ! ok {
150- return ret , ErrClosed
164+ return ret , ErrStopped
151165 }
152166 ret = append (ret , item )
153167 case <- time .After (300 * time .Millisecond ):
0 commit comments