diff --git a/pkg/sql/logictest/logic.go b/pkg/sql/logictest/logic.go index c1607c698d18..136f168ff222 100644 --- a/pkg/sql/logictest/logic.go +++ b/pkg/sql/logictest/logic.go @@ -27,6 +27,7 @@ import ( "sort" "strconv" "strings" + "sync/atomic" "testing" "text/tabwriter" "time" @@ -1126,7 +1127,7 @@ type logicTest struct { // allowUnsafe is a variable which controls whether the test can access // unsafe internals. - allowUnsafe bool + allowUnsafe atomic.Bool } func (t *logicTest) t() *testing.T { @@ -1501,7 +1502,10 @@ func (t *logicTest) newCluster( DisableOptimizerRuleProbability: *disableOptRuleProbability, OptimizerCostPerturbation: *optimizerCostPerturbation, ForceProductionValues: serverArgs.ForceProductionValues, - UnsafeOverride: func() *bool { return &t.allowUnsafe }, + UnsafeOverride: func() *bool { + v := t.allowUnsafe.Load() + return &v + }, } knobs.SQLExecutor = &sql.ExecutorTestingKnobs{ DeterministicExplain: true, @@ -4649,8 +4653,8 @@ func RunLogicTest( perErrorSummary: make(map[string][]string), rng: rng, declarativeCorpusCollector: cc, - allowUnsafe: true, } + lt.allowUnsafe.Store(true) if *printErrorSummary { defer lt.printErrorSummary() } @@ -4940,8 +4944,8 @@ func (t *logicTest) setSafetyGate(sql string, skip bool) func() { return func() {} } - t.allowUnsafe = false + t.allowUnsafe.Store(false) return func() { - t.allowUnsafe = true + t.allowUnsafe.Store(true) } } diff --git a/pkg/sql/logictest/parallel_test.go b/pkg/sql/logictest/parallel_test.go index 7149d1ee255f..da04b5baa2bd 100644 --- a/pkg/sql/logictest/parallel_test.go +++ b/pkg/sql/logictest/parallel_test.go @@ -67,15 +67,15 @@ func (t *parallelTest) processTestFile(path string, nodeIdx int, db *gosql.DB, c // Set up a dummy logicTest structure to use that code. rng, _ := randutil.NewTestRand() l := &logicTest{ - rootT: t.T, - cluster: t.cluster, - nodeIdx: nodeIdx, - db: db, - user: username.RootUser, - verbose: testing.Verbose() || log.V(1), - rng: rng, - allowUnsafe: true, + rootT: t.T, + cluster: t.cluster, + nodeIdx: nodeIdx, + db: db, + user: username.RootUser, + verbose: testing.Verbose() || log.V(1), + rng: rng, } + l.allowUnsafe.Store(true) if err := l.processTestFile(path, logictest.TestClusterConfig{}); err != nil { log.Dev.Errorf(context.Background(), "error processing %s: %s", path, err) t.Error(err)