diff --git a/pkg/util/grunning/BUILD.bazel b/pkg/util/grunning/BUILD.bazel index e516ce296a79..469bb1d851bd 100644 --- a/pkg/util/grunning/BUILD.bazel +++ b/pkg/util/grunning/BUILD.bazel @@ -23,41 +23,49 @@ go_test( "@io_bazel_rules_go//go/platform:aix_ppc64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:android_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:android_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:android_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:android_arm64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:darwin_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:darwin_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:darwin_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:darwin_arm64": [ @@ -67,6 +75,7 @@ go_test( "@io_bazel_rules_go//go/platform:dragonfly_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:freebsd_386": [ @@ -88,11 +97,13 @@ go_test( "@io_bazel_rules_go//go/platform:illumos_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:ios_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:ios_arm64": [ @@ -102,141 +113,169 @@ go_test( "@io_bazel_rules_go//go/platform:js_wasm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_arm64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_mips": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_mips64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_mips64le": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_mipsle": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_ppc64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_ppc64le": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_riscv64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:linux_s390x": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:netbsd_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:netbsd_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:netbsd_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:netbsd_arm64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:openbsd_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:openbsd_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:openbsd_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:openbsd_arm64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:plan9_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:plan9_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:plan9_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:solaris_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:windows_386": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:windows_amd64": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "@io_bazel_rules_go//go/platform:windows_arm": [ ":grunning", "//pkg/testutils/skip", + "//pkg/util/syncutil", "@com_github_stretchr_testify//require", ], "//conditions:default": [], diff --git a/pkg/util/grunning/enabled_test.go b/pkg/util/grunning/enabled_test.go index a3b864bc0738..fc5379d1a95f 100644 --- a/pkg/util/grunning/enabled_test.go +++ b/pkg/util/grunning/enabled_test.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/testutils/skip" "github.com/cockroachdb/cockroach/pkg/util/grunning" + "github.com/cockroachdb/cockroach/pkg/util/syncutil" "github.com/stretchr/testify/require" ) @@ -89,8 +90,11 @@ func TestEquivalentGoroutines(t *testing.T) { // package. func TestProportionalGoroutines(t *testing.T) { skip.UnderStress(t, "not applicable") - - f := func(wg *sync.WaitGroup, v uint64, trip uint64, result *int64) { + type resultContainer struct { + mu *syncutil.Mutex + value int64 + } + f := func(wg *sync.WaitGroup, v uint64, trip uint64, result *resultContainer) { defer wg.Done() ret := v @@ -100,10 +104,17 @@ func TestProportionalGoroutines(t *testing.T) { } nanos := grunning.Time().Nanoseconds() - *result = nanos + result.mu.Lock() + defer result.mu.Unlock() + result.value = nanos } - results := make([]int64, 10) + results := make([]resultContainer, 10) + for i := 0; i < len(results); i++ { + results[i] = resultContainer{ + mu: &syncutil.Mutex{}, + } + } var wg sync.WaitGroup for iters := 0; iters < 10000; iters++ { @@ -118,13 +129,13 @@ func TestProportionalGoroutines(t *testing.T) { total := int64(0) for _, result := range results { - total += result + total += result.value } - initial := float64(results[0]) / float64(total) + initial := float64(results[0].value) / float64(total) for i, result := range results { - got := float64(result) / float64(total) + got := float64(result.value) / float64(total) mult := got / initial t.Logf("thread=%02d got %5.2f%% of on-cpu time: expected≈%5.2fx got=%4.2fx ", i+1, got*100, float64(i+1), mult)