From e890e03d68697d4dabdf4b7582d732a20199fd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Thu, 16 Apr 2020 15:03:39 +0200 Subject: [PATCH] tests/image: run the tests in parallel (somewhat) This commits enables the parallelism for the image tests. However, there's a catch. Osbuild cannot be reliably run in parallel, so the code uses a mutex to ensure there's always only one osbuild instance for now. Even with this limitation, there's a significant speed-up of the tests: Prior this commit, the image tests run in 40 minutes on Travis. After this commit, the time is reduced to 32 minutes. The speed-up will have an even bigger effect when more cloud-upload tests are added to the test suite. --- cmd/osbuild-image-tests/main_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/osbuild-image-tests/main_test.go b/cmd/osbuild-image-tests/main_test.go index c09af766c..c890fb689 100644 --- a/cmd/osbuild-image-tests/main_test.go +++ b/cmd/osbuild-image-tests/main_test.go @@ -15,6 +15,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "testing" "time" @@ -37,8 +38,17 @@ type testcaseStruct struct { } } +// mutex to enforce only one osbuild instance run at a time, see below +var osbuildMutex sync.Mutex + // runOsbuild runs osbuild with the specified manifest and store. func runOsbuild(manifest []byte, store string) (string, error) { + // Osbuild crashes when multiple instances are run at a time. + // This mutex enforces that there's always just one osbuild instance. + // This should be removed once osbuild is fixed. + // See https://github.com/osbuild/osbuild/issues/351 + osbuildMutex.Lock() + defer osbuildMutex.Unlock() cmd := getOsbuildCommand(store) cmd.Stderr = os.Stderr @@ -402,6 +412,13 @@ func runTests(t *testing.T, cases []string) { t.Skipf("the required arch is %s, the current arch is %s", testcase.ComposeRequest.Arch, currentArch) } + // Run the test in parallel + // The t.Parallel() call is after the skip conditions, because + // the skipped tests are short and there's no need to run + // them in parallel and create more goroutines. + // Also the output is clearer this way. + t.Parallel() + runTestcase(t, testcase) })