File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 66 "fmt"
77 "math/rand"
88 "reflect"
9+ "sync"
910 "testing"
1011 "time"
1112
@@ -91,7 +92,7 @@ func Test_BatchWorkflow(t *testing.T) {
9192 env .RegisterActivity (batchActivity )
9293
9394 totalSize := 100
94- concurrency := 10
95+ concurrency := 20
9596
9697 startTime := time .Now ()
9798 env .ExecuteWorkflow (batchWorkflow , batchWorkflowInput {
@@ -119,20 +120,23 @@ func Test_BatchWorkflow_Cancel(t *testing.T) {
119120 env .RegisterActivity (batchActivity )
120121
121122 totalSize := 100
122- concurrency := 10
123+ concurrency := 20
124+
125+ totalExpectedTime := time .Second * time .Duration (1 + totalSize / concurrency )
126+ wg := sync.WaitGroup {}
127+ wg .Add (1 )
123128 go func () {
129+ defer wg .Done ()
124130 env .ExecuteWorkflow (batchWorkflow , batchWorkflowInput {
125131 Concurrency : concurrency ,
126132 TotalSize : totalSize ,
127133 })
128134 }()
129135
130- totalExpectedTime := time .Second * time .Duration (totalSize / concurrency )
131-
132136 time .Sleep (totalExpectedTime / 2 )
133137 env .CancelWorkflow ()
134138
135- time . Sleep ( totalExpectedTime / 2 )
139+ wg . Wait () // wait for the workflow to complete otherwise test env will have race condition
136140 assert .True (t , env .IsWorkflowCompleted ())
137141
138142 err := env .GetWorkflowError ()
You can’t perform that action at this time.
0 commit comments