-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
job_monitor_test.go
63 lines (52 loc) · 2.09 KB
/
job_monitor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright 2021 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
package persistedsqlstats_test
import (
"context"
"testing"
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/server"
"github.com/cockroachdb/cockroach/pkg/sql/tests"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
)
func TestVersionGating(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
ctx := context.Background()
params, _ := tests.CreateTestServerParams()
params.Knobs.Server = &server.TestingKnobs{
DisableAutomaticVersionUpgrade: 1,
BinaryVersionOverride: clusterversion.ByKey(clusterversion.SQLStatsCompactionScheduledJob - 1),
}
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{
ServerArgs: params,
})
defer tc.Stopper().Stop(ctx)
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0 /* idx */))
sqlDB.CheckQueryResults(t,
"SELECT count(*) FROM [SHOW SCHEDULES FOR SQL STATISTICS]",
[][]string{{"0"}})
sqlDB.Exec(t, `SET CLUSTER SETTING version = $1`,
clusterversion.ByKey(clusterversion.SQLStatsCompactionScheduledJob).String())
// Change the recurrence cluster setting to force job monitor to create the
// sql stats compaction schedule.
sqlDB.Exec(t, "SET CLUSTER SETTING sql.stats.cleanup.recurrence = '@daily'")
// Wait for the change is picked up by the job monitor.
sqlDB.CheckQueryResultsRetry(t,
"SELECT recurrence FROM [SHOW SCHEDULES FOR SQL STATISTICS]",
[][]string{{"@daily"}})
sqlDB.CheckQueryResults(t,
"SELECT count(*) FROM [SHOW SCHEDULES FOR SQL STATISTICS]",
[][]string{{"1"}})
}