@@ -23,9 +23,10 @@ func TestWorkerContext(t *testing.T) {
2323 })
2424
2525 t .Run ("Dedicated" , func (t * testing.T ) {
26- ctx := context .WithValue (context .Background (), "1" , "2" )
26+ type ctxkey struct {}
27+ ctx := context .WithValue (context .Background (), ctxkey {}, "2" )
2728 w := NewWorker (ctx )
28- require .Equal (t , "2" , w .Context ().Value ("1" ))
29+ require .Equal (t , "2" , w .Context ().Value (ctxkey {} ))
2930 })
3031
3132 t .Run ("Stop" , func (t * testing.T ) {
@@ -96,7 +97,7 @@ func TestWorkerClose(t *testing.T) {
9697
9798func TestWorkerConcurrentStartAndClose (t * testing.T ) {
9899 xtest .TestManyTimes (t , func (t testing.TB ) {
99- targetClose := int64 (10000 )
100+ targetClose := int64 (100 )
100101 parallel := 10
101102
102103 var counter int64
@@ -106,13 +107,16 @@ func TestWorkerConcurrentStartAndClose(t *testing.T) {
106107
107108 closeIndex := int64 (0 )
108109 closed := make (empty.Chan )
110+
109111 go func () {
112+ defer close (closed )
113+
110114 xtest .SpinWaitCondition (t , nil , func () bool {
111115 return atomic .LoadInt64 (& counter ) > targetClose
112116 })
117+
113118 require .NoError (t , w .Close (ctx , nil ))
114119 closeIndex = atomic .LoadInt64 (& counter )
115- close (closed )
116120 }()
117121
118122 stopNewStarts := xatomic.Bool {}
@@ -123,11 +127,9 @@ func TestWorkerConcurrentStartAndClose(t *testing.T) {
123127 return
124128 }
125129
126- go func () {
127- w .Start ("test" , func (ctx context.Context ) {
128- atomic .AddInt64 (& counter , 1 )
129- })
130- }()
130+ w .Start ("test" , func (ctx context.Context ) {
131+ atomic .AddInt64 (& counter , 1 )
132+ })
131133 }
132134 }()
133135 }
0 commit comments