Skip to content

Commit

Permalink
tests: fix check to enable the race detector in supported platforms (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mauri870 authored Sep 16, 2024
1 parent 42fb7a8 commit a4387db
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions dev-tools/mage/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/exec"
"path"
"path/filepath"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a4387db

Please sign in to comment.