Add t.Parallel() to SDK tests
Reduces time to run go test ./sdk from 44 seconds to 22.5 seconds.
Requires moving snapshotTestCustomizations from a map to a struct
with individual fields to avoid concurrent map accesses between
subtests.
Test: go test ./sdk
Change-Id: Id6f451ba9cbace8bc7ea915033a795456b85cf3f
diff --git a/sdk/testing.go b/sdk/testing.go
index 21d457c..f5518c4 100644
--- a/sdk/testing.go
+++ b/sdk/testing.go
@@ -128,12 +128,11 @@
// generated, etc.
func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) *snapshotBuildInfo {
info := &snapshotBuildInfo{
- t: t,
- r: result,
- androidBpContents: sdk.GetAndroidBpContentsForTests(),
- infoContents: sdk.GetInfoContentsForTests(),
- snapshotTestCustomizations: map[snapshotTest]*snapshotTestCustomization{},
- targetBuildRelease: sdk.builderForTests.targetBuildRelease,
+ t: t,
+ r: result,
+ androidBpContents: sdk.GetAndroidBpContentsForTests(),
+ infoContents: sdk.GetInfoContentsForTests(),
+ targetBuildRelease: sdk.builderForTests.targetBuildRelease,
}
buildParams := sdk.BuildParamsForTests()
@@ -293,6 +292,7 @@
}
t.Run("snapshot without source", func(t *testing.T) {
+ t.Parallel()
// Remove the source Android.bp file to make sure it works without.
removeSourceAndroidBp := android.FixtureModifyMockFS(func(fs android.MockFS) {
delete(fs, "Android.bp")
@@ -302,10 +302,12 @@
})
t.Run("snapshot with source preferred", func(t *testing.T) {
+ t.Parallel()
runSnapshotTestWithCheckers(t, checkSnapshotWithSourcePreferred, android.NullFixturePreparer)
})
t.Run("snapshot preferred with source", func(t *testing.T) {
+ t.Parallel()
// Replace the snapshot/Android.bp file with one where "prefer: false," has been replaced with
// "prefer: true,"
preferPrebuilts := android.FixtureModifyMockFS(func(fs android.MockFS) {
@@ -469,19 +471,40 @@
targetBuildRelease *buildRelease
// The test specific customizations for each snapshot test.
- snapshotTestCustomizations map[snapshotTest]*snapshotTestCustomization
+ snapshotTestCustomizations snapshotTestCustomizationSet
+}
+
+type snapshotTestCustomizationSet struct {
+ snapshotWithoutSource *snapshotTestCustomization
+ snapshotWithSourcePreferred *snapshotTestCustomization
+ snapshotPreferredWithSource *snapshotTestCustomization
+}
+
+func (s *snapshotTestCustomizationSet) customization(snapshotTest snapshotTest) **snapshotTestCustomization {
+ var customization **snapshotTestCustomization
+ switch snapshotTest {
+ case checkSnapshotWithoutSource:
+
+ customization = &s.snapshotWithoutSource
+ case checkSnapshotWithSourcePreferred:
+ customization = &s.snapshotWithSourcePreferred
+ case checkSnapshotPreferredWithSource:
+ customization = &s.snapshotPreferredWithSource
+ default:
+ panic(fmt.Errorf("unsupported snapshotTest %v", snapshotTest))
+ }
+ return customization
}
// snapshotTestCustomization gets the test specific customization for the specified snapshotTest.
//
// If no customization was created previously then it creates a default customization.
func (i *snapshotBuildInfo) snapshotTestCustomization(snapshotTest snapshotTest) *snapshotTestCustomization {
- customization := i.snapshotTestCustomizations[snapshotTest]
- if customization == nil {
- customization = &snapshotTestCustomization{
+ customization := i.snapshotTestCustomizations.customization(snapshotTest)
+ if *customization == nil {
+ *customization = &snapshotTestCustomization{
errorHandler: android.FixtureExpectsNoErrors,
}
- i.snapshotTestCustomizations[snapshotTest] = customization
}
- return customization
+ return *customization
}