Skip to content

Commit ad26792

Browse files
committed
build: add crdb_bench flag
A recent change (#148576) causes some test initializations to throw a panic if the binary was not build with `crdb_test`. ``` ./dev bench pkg/sql/catalog/lease -f=BenchmarkAcquireLeaseConcurrent $ bazel test pkg/sql/catalog/lease:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkAcquireLeaseConcurrent --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=/Users/herko/Library/Caches/crdb-test-fixtures --sandbox_writable_path=/Users/herko/Library/Caches/crdb-test-fixtures --test_output streamed panic: Testing override for schema_locked used in non-test binary. goroutine 1 [running]: github.com/cockroachdb/cockroach/pkg/sql.TestForceDisableCreateTableWithSchemaLocked(...) pkg/sql/exec_util.go:773 github.com/cockroachdb/cockroach/pkg/sql/catalog/lease_test.TestMain(0x1400132e620?) pkg/sql/catalog/lease/main_test.go:29 +0xcc main.main() ``` This is problematic for benchmarks, which are not built with `crdb_test`. Benchmarks are not built with the `crdb_test` flag, because this flag enables metamorphic variables and extra assertions which could interfere with performance testing. This change adds a new `crdb_bench` flag, which is disabled by default. The assertions added in #148576 is now also skipped when `crdb_bench` is enabled. Informs: #148576 Fixes: #149339 Epic: None Release note: None
1 parent 7a762aa commit ad26792

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
2222
build --flag_alias=bazel_code_coverage=//build/toolchains:bazel_code_coverage_flag
2323
build --flag_alias=crdb_test=//build/toolchains:crdb_test_flag
2424
build --flag_alias=crdb_test_off=//build/toolchains:crdb_test_off_flag
25+
build --flag_alias=crdb_bench=//build/toolchains:crdb_bench_flag
2526
build --flag_alias=cross=//build/toolchains:cross_flag
2627
build --flag_alias=dev=//build/toolchains:dev_flag
2728
build --flag_alias=force_build_cdeps=//build/toolchains:force_build_cdeps_flag

build/toolchains/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,19 @@ config_setting(
299299
},
300300
)
301301

302+
bool_flag(
303+
name = "crdb_bench_flag",
304+
build_setting_default = False,
305+
visibility = ["//visibility:public"],
306+
)
307+
308+
config_setting(
309+
name = "crdb_bench",
310+
flag_values = {
311+
":crdb_bench_flag": "true",
312+
},
313+
)
314+
302315
bool_flag(
303316
name = "dev_flag",
304317
build_setting_default = False,

pkg/util/buildutil/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

3+
# gazelle:exclude gen-crdb_bench_off.go
4+
# gazelle:exclude gen-crdb_bench_on.go
35
# gazelle:exclude gen-crdb_test_off.go
46
# gazelle:exclude gen-crdb_test_on.go
57

@@ -9,13 +11,30 @@ go_library(
911
srcs = select({
1012
"//build/toolchains:crdb_test": [":gen-crdb-test-on"],
1113
"//conditions:default": [":gen-crdb-test-off"],
14+
}) + select({
15+
"//build/toolchains:crdb_bench": [":gen-crdb-bench-on"],
16+
"//conditions:default": [":gen-crdb-bench-off"],
1217
}),
1318
importpath = "github.com/cockroachdb/cockroach/pkg/util/buildutil",
1419
visibility = ["//visibility:public"],
1520
)
1621

1722
REMOVE_GO_BUILD_CONSTRAINTS = "cat $< | grep -v '//go:build' | grep -v '// +build' > $@"
1823

24+
genrule(
25+
name = "gen-crdb-bench-on",
26+
srcs = ["crdb_bench_on.go"],
27+
outs = ["gen-crdb_bench_on.go"],
28+
cmd = REMOVE_GO_BUILD_CONSTRAINTS,
29+
)
30+
31+
genrule(
32+
name = "gen-crdb-bench-off",
33+
srcs = ["crdb_bench_off.go"],
34+
outs = ["gen-crdb_bench_off.go"],
35+
cmd = REMOVE_GO_BUILD_CONSTRAINTS,
36+
)
37+
1938
genrule(
2039
name = "gen-crdb-test-on",
2140
srcs = ["crdb_test_on.go"],
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
//go:build !crdb_bench || crdb_bench_off
7+
8+
// Package buildutil provides a constant CrdbBenchBuild.
9+
package buildutil
10+
11+
// CrdbBenchBuild is a flag that is set to true if the binary was compiled
12+
// with the 'crdb_bench' build tag (which is the case for all benchmark targets).
13+
const CrdbBenchBuild = false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
//go:build crdb_bench && !crdb_bench_off
7+
8+
// Package buildutil provides a constant CrdbBenchBuild.
9+
package buildutil
10+
11+
// CrdbBenchBuild is a flag that is set to true if the binary was compiled
12+
// with the 'crdb_bench' build tag (which is the case for all benchmark targets).
13+
const CrdbBenchBuild = true

0 commit comments

Comments
 (0)