@@ -76,9 +76,13 @@ func TestRemoveWorkerThenShutdown(t *testing.T) {
7676 rdb = redis .NewClient (& redis.Options {Addr : "localhost:6379" , Password : redisPwd })
7777 node = newTestNode (t , ctx , rdb , testName )
7878 worker = newTestWorker (t , ctx , node )
79+ handler = worker .handler .(* mockHandler )
7980 )
8081 defer cleanup (t , rdb , true , testName )
82+ assert .NoError (t , node .DispatchJob (ctx , testName , []byte ("payload" )))
83+ assert .Eventually (t , func () bool { return len (handler .jobs ) == 1 }, max , delay )
8184 assert .NoError (t , node .RemoveWorker (ctx , worker ))
85+ assert .Eventually (t , func () bool { return len (handler .jobs ) == 0 }, max , delay )
8286 assert .NoError (t , node .Shutdown (ctx ))
8387}
8488
@@ -88,9 +92,14 @@ func TestClose(t *testing.T) {
8892 testName = strings .Replace (t .Name (), "/" , "_" , - 1 )
8993 rdb = redis .NewClient (& redis.Options {Addr : "localhost:6379" , Password : redisPwd })
9094 node = newTestNode (t , ctx , rdb , testName )
95+ worker = newTestWorker (t , ctx , node )
96+ handler = worker .handler .(* mockHandler )
9197 )
9298 defer cleanup (t , rdb , false , testName )
99+ assert .NoError (t , node .DispatchJob (ctx , testName , []byte ("payload" )))
100+ assert .Eventually (t , func () bool { return len (handler .jobs ) == 1 }, max , delay )
93101 assert .NoError (t , node .Close (ctx ))
102+ assert .Eventually (t , func () bool { return len (handler .jobs ) == 0 }, max , delay )
94103}
95104
96105func newTestNode (t * testing.T , ctx context.Context , rdb * redis.Client , name string ) * Node {
@@ -106,11 +115,11 @@ func newTestNode(t *testing.T, ctx context.Context, rdb *redis.Client, name stri
106115
107116func newTestWorker (t * testing.T , ctx context.Context , node * Node ) * Worker {
108117 t .Helper ()
109- wm := & workerMock {jobs : make (map [string ]* Job )}
110- wm .startFunc = func (job * Job ) error { wm .jobs [job .Key ] = job ; return nil }
111- wm .stopFunc = func (key string ) error { delete (wm .jobs , key ); return nil }
112- wm .notifyFunc = func (payload []byte ) error { return nil }
113- worker , err := node .AddWorker (ctx , wm )
118+ handler := & mockHandler {jobs : make (map [string ]* Job )}
119+ handler .startFunc = func (job * Job ) error { handler .jobs [job .Key ] = job ; return nil }
120+ handler .stopFunc = func (key string ) error { delete (handler .jobs , key ); return nil }
121+ handler .notifyFunc = func (payload []byte ) error { return nil }
122+ worker , err := node .AddWorker (ctx , handler )
114123 require .NoError (t , err )
115124 return worker
116125}
@@ -150,16 +159,16 @@ func cleanup(t *testing.T, rdb *redis.Client, checkClean bool, testName string)
150159 assert .NoError (t , rdb .FlushDB (ctx ).Err ())
151160}
152161
153- type workerMock struct {
162+ type mockHandler struct {
154163 startFunc func (job * Job ) error
155164 stopFunc func (key string ) error
156165 notifyFunc func (payload []byte ) error
157166 jobs map [string ]* Job
158167}
159168
160- func (w * workerMock ) Start (job * Job ) error { return w .startFunc (job ) }
161- func (w * workerMock ) Stop (key string ) error { return w .stopFunc (key ) }
162- func (w * workerMock ) Notify (p []byte ) error { return w .notifyFunc (p ) }
169+ func (w * mockHandler ) Start (job * Job ) error { return w .startFunc (job ) }
170+ func (w * mockHandler ) Stop (key string ) error { return w .stopFunc (key ) }
171+ func (w * mockHandler ) Notify (p []byte ) error { return w .notifyFunc (p ) }
163172
164173// buffer is a goroutine safe bytes.Buffer
165174type buffer struct {
0 commit comments