inmemory: add a test for the ListTypes race fix (#5327)

Add a test that interleaves calls to Put() (with different type strings)
and ListTypes(). At least on my machine, this appears to reliably detect
the data race fixed in commit 2f8743522d
when run with the Go race detector. (The 'make test' and 'make cover'
targets run with the Go race detector enabled.)
This commit is contained in:
Kenneth Jenkins 2024-10-15 15:32:29 -07:00 committed by GitHub
parent 11054a943d
commit 298a5a94a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -252,3 +252,17 @@ func TestLease(t *testing.T) {
assert.True(t, ok, "expected b to to acquire the lease")
}
}
// Concurrent calls to Put() and ListTypes() should not cause a data race.
func TestListTypes_concurrent(_ *testing.T) {
ctx := context.Background()
backend := New()
for i := 0; i < 10; i++ {
t := fmt.Sprintf("Type-%02d", i)
go backend.Put(ctx, []*databroker.Record{{
Id: "1",
Type: t,
}})
go backend.ListTypes(ctx)
}
}