-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathworker_test.go
More file actions
46 lines (37 loc) · 840 Bytes
/
worker_test.go
File metadata and controls
46 lines (37 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package tempts
import (
"context"
"testing"
"time"
"go.temporal.io/sdk/testsuite"
"go.temporal.io/sdk/worker"
)
func TestWorkerRunReturnsOnContextCancel(t *testing.T) {
srv, err := testsuite.StartDevServer(context.Background(), testsuite.DevServerOptions{
LogLevel: "error",
})
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { srv.Stop() })
c, err := NewFromSDK(srv.Client(), "default")
if err != nil {
t.Fatal(err)
}
q := NewQueue("worker-cancel-test")
wrk, err := NewWorker(q, nil)
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() {
done <- wrk.Run(ctx, c, worker.Options{})
}()
cancel()
select {
case <-done:
case <-time.After(5 * time.Second):
t.Fatal("Worker.Run did not return after context cancellation")
}
}