Fix data race in snapshot singletons when running parallel tests
Singleton objects need to be created in the singleton factory rather
than as a global variable so that they have a unique object per
context in order to allow multiple tests to run in parallel.
Test: go test -race ./...
Change-Id: Ib6912849e1b849ffe8646882cfb476ddea6c6b55
diff --git a/snapshot/recovery_snapshot.go b/snapshot/recovery_snapshot.go
index 8ff59cb..ab114b4 100644
--- a/snapshot/recovery_snapshot.go
+++ b/snapshot/recovery_snapshot.go
@@ -22,16 +22,14 @@
ExcludeFromRecoverySnapshot() bool
}
-var recoverySnapshotSingleton = SnapshotSingleton{
- "recovery", // name
- "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
- android.OptionalPath{}, // snapshotZipFile
- RecoverySnapshotImageSingleton, // Image
- false, // Fake
-}
-
func RecoverySnapshotSingleton() android.Singleton {
- return &recoverySnapshotSingleton
+ return &SnapshotSingleton{
+ "recovery", // name
+ "SOONG_RECOVERY_SNAPSHOT_ZIP", // makeVar
+ android.OptionalPath{}, // snapshotZipFile
+ RecoverySnapshotImageSingleton, // Image
+ false, // Fake
+ }
}
// Determine if a dir under source tree is an SoC-owned proprietary directory based