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
parent a8c04a9c7d
commit c633a68afb

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)
}
}