Skip to content

Commit 740357b

Browse files
committed
fix test racing again
1 parent f38851b commit 740357b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

internal/batch/batch_future_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
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()

0 commit comments

Comments
 (0)