Open delanne opened 1 week ago
To clarify, are you seeing this data race when the same test environment being shared by multiple tests?
To clarify, are you seeing this data race when the same test environment being shared by multiple tests?
all tests are run in parallel. Here is an example of how I write a test
func Test_Activity_FooBar(t *testing.T) {
testSuite := &testsuite.WorkflowTestSuite{}
env := testSuite.NewTestActivityEnvironment()
env.RegisterActivity(FooBar)
t.Parallel()
tests := []struct {
name string
p *FooBarParams
expected internal.Return
}{
{
name: "foobar test1",
p: &FooBarParams{
String1: "foobar",
String2: "foobar",
},
expected: internal.Return{Value: float64(0)},
},
.....
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
val, err := env.ExecuteActivity(FooBar,
tt.p,
)
require.NoError(t, err)
res := &internal.Return{}
err = val.Get(res)
require.NoError(t, err)
require.Equal(t, &tt.expected, res)
})
}
}
Do you mean that the line env := testSuite.NewTestActivityEnvironment()
should be after the line t.Parallel()
? (make sense to me)
Expected Behavior
Actual Behavior
when testing several Activities with t.Parallel, the test framework crash with "fatal error: concurrent map writes"
Steps to Reproduce the Problem
Specifications
Investigation
code:
as several go routines can write in the map 'activities', the type of activities should be a sync.Map or use a mutex to protect the write
Potential fix
internal/internal_workflow_testsuite.go:1415