From a4387db9e98138cbd1857938150c037bfaa5e629 Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Mon, 16 Sep 2024 09:45:07 -0300 Subject: [PATCH] tests: fix check to enable the race detector in supported platforms (#40764) * tests: fix check to enable the race detector in supported platforms This code is almost 4 years old, the support for the race detector was lacking at that point and Elastic had its first steps with arm64 builds of Beats. I updated the check to allow tests to run with RACE_DETECTOR=true in supported platforms, this includes linux/arm64 and darwin/arm64. * add log if race is enabled for an unsupported platform --- dev-tools/mage/gotest.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 5d507c65aa4..d8244403c9c 100644 --- a/dev-tools/mage/gotest.go +++ b/dev-tools/mage/gotest.go @@ -27,6 +27,7 @@ import ( "os/exec" "path" "path/filepath" + "slices" "strings" "time" @@ -273,10 +274,20 @@ func GoTest(ctx context.Context, params GoTestArgs) error { var testArgs []string - // -race is only supported on */amd64 - if os.Getenv("DEV_ARCH") == "amd64" { - if params.Race { + if params.Race { + // Enable the race detector for supported platforms. + // This is an intersection of the supported platforms for Beats and Go. + // + // See https://go.dev/doc/articles/race_detector#Requirements. + devOS := os.Getenv("DEV_OS") + devArch := os.Getenv("DEV_ARCH") + raceAmd64 := devArch == "amd64" + raceArm64 := devArch == "arm64" && + slices.Contains([]string{"linux", "darwin"}, devOS) + if raceAmd64 || raceArm64 { testArgs = append(testArgs, "-race") + } else { + log.Printf("Warning: skipping -race flag for unsupported platform %s/%s\n", devOS, devArch) } } if len(params.Tags) > 0 {