diff --git a/dev-tools/mage/gotest.go b/dev-tools/mage/gotest.go index 5d507c65aa4d..d8244403c9cc 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 {