Skip to content

Commit 4c2d4c3

Browse files
committed
kvserver: fix rebalance obj test on arm mac
Previosly,`TestRebalanceObjectiveManager` and `TestLoadBasedRebalancingObjective` would assert assuming that it was possible for the test host to use `grunning`, however this is not true for ARM Mac. This patch ammends these tests to test a subset of behavior when `grunning` isn't supported and then exit. Fixes: #96934 Release note: None
1 parent 5f310bc commit 4c2d4c3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pkg/kv/kvserver/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ go_test(
430430
"//pkg/util/ctxgroup",
431431
"//pkg/util/encoding",
432432
"//pkg/util/errorutil",
433+
"//pkg/util/grunning",
433434
"//pkg/util/hlc",
434435
"//pkg/util/humanizeutil",
435436
"//pkg/util/leaktest",

pkg/kv/kvserver/rebalance_objective_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/allocator/storepool"
1919
"github.com/cockroachdb/cockroach/pkg/roachpb"
2020
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
21+
"github.com/cockroachdb/cockroach/pkg/util/grunning"
2122
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
2223
"github.com/cockroachdb/cockroach/pkg/util/log"
2324
"github.com/stretchr/testify/require"
@@ -82,6 +83,29 @@ func TestLoadBasedRebalancingObjective(t *testing.T) {
8283
defer log.Scope(t).Close(t)
8384
ctx := context.Background()
8485

86+
// On ARM MacOS and other architectures, grunning isn't supported so
87+
// changing the objective to CPU should never work. If this test is run on
88+
// one of these unsupported aarch, test this behavior only.
89+
if !grunning.Supported() {
90+
st := cluster.MakeTestingClusterSettings()
91+
92+
gossipStoreDescProvider := testMakeProviderNotifier(allPositiveCPUMap)
93+
LoadBasedRebalancingObjective.Override(ctx, &st.SV, int64(LBRebalancingQueries))
94+
require.Equal(t,
95+
LBRebalancingQueries,
96+
ResolveLBRebalancingObjective(ctx, st, gossipStoreDescProvider.GetStores()),
97+
)
98+
99+
// Despite setting to CPU, only QPS should be returned since this aarch
100+
// doesn't support grunning.
101+
LoadBasedRebalancingObjective.Override(ctx, &st.SV, int64(LBRebalancingCPU))
102+
require.Equal(t,
103+
LBRebalancingQueries,
104+
ResolveLBRebalancingObjective(ctx, st, gossipStoreDescProvider.GetStores()),
105+
)
106+
return
107+
}
108+
85109
t.Run("latest version supports all rebalance objectives", func(t *testing.T) {
86110
st := cluster.MakeTestingClusterSettings()
87111
gossipStoreDescProvider := testMakeProviderNotifier(allPositiveCPUMap)
@@ -168,6 +192,26 @@ func TestRebalanceObjectiveManager(t *testing.T) {
168192
), &callbacks
169193
}
170194

195+
// On ARM MacOS and other architectures, grunning isn't supported so
196+
// changing the objective to CPU should never work. If this test is run on
197+
// one of these unsupported aarch, test this behavior only.
198+
if !grunning.Supported() {
199+
st := cluster.MakeTestingClusterSettings()
200+
LoadBasedRebalancingObjective.Override(ctx, &st.SV, int64(LBRebalancingQueries))
201+
providerNotifier := testMakeProviderNotifier(allPositiveCPUMap)
202+
manager, callbacks := makeTestManager(st, providerNotifier)
203+
204+
require.Equal(t, LBRebalancingQueries, manager.Objective())
205+
206+
// Changing the objective to CPU should not work since it isn't
207+
// supported on this aarch.
208+
LoadBasedRebalancingObjective.Override(ctx, &st.SV, int64(LBRebalancingCPU))
209+
require.Equal(t, LBRebalancingCPU, manager.Objective())
210+
require.Len(t, *callbacks, 0)
211+
212+
return
213+
}
214+
171215
t.Run("latest version", func(t *testing.T) {
172216
st := cluster.MakeTestingClusterSettings()
173217
LoadBasedRebalancingObjective.Override(ctx, &st.SV, int64(LBRebalancingCPU))

0 commit comments

Comments
 (0)