From fa29885380342aa4adb82e7cffea4bd5d3e78cfd Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 8 Mar 2021 15:05:24 +0000 Subject: [PATCH] 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 --- android/fixture.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/android/fixture.go b/android/fixture.go index 2c8997bd2..2085e43ed 100644 --- a/android/fixture.go +++ b/android/fixture.go @@ -564,7 +564,11 @@ type fixtureFactory struct { } 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. extendedFactory := &fixtureFactory{} *extendedFactory = *f