Avoid accidentally sharing preparers slice across factories

Previously, there was a bug that caused tests which ran successfully on
their own to fail when run together in parallel. They each extended the
same factory and ended up sharing the preparers slice which meant that
they overwrote each other's preparers causing the tests to fail.

This change fixes that by creating a new slice for each factory.

Bug: 181070625
Test: m nothing
Change-Id: If340c125c5b03a9d5c36a59ff4da4ec189808f9b
This commit is contained in:
Paul Duffin
2021-03-08 15:05:24 +00:00
parent 5a5eeace54
commit fa29885380

View File

@@ -564,7 +564,11 @@ type fixtureFactory struct {
} }
func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixtureFactory { func (f *fixtureFactory) Extend(preparers ...FixturePreparer) FixtureFactory {
all := append(f.preparers, dedupAndFlattenPreparers(f.preparers, preparers)...) // Create a new slice to avoid accidentally sharing the preparers slice from this factory with
// the extending factories.
var all []*simpleFixturePreparer
all = append(all, f.preparers...)
all = append(all, dedupAndFlattenPreparers(f.preparers, preparers)...)
// Copy the existing factory. // Copy the existing factory.
extendedFactory := &fixtureFactory{} extendedFactory := &fixtureFactory{}
*extendedFactory = *f *extendedFactory = *f