-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
builtins_test.go
63 lines (54 loc) · 2.21 KB
/
builtins_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 upgrades_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/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
)
func TestIsAtLeastVersionBuiltin(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)
clusterArgs := base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
Knobs: base.TestingKnobs{
Server: &server.TestingKnobs{
DisableAutomaticVersionUpgrade: make(chan struct{}),
BinaryVersionOverride: clusterversion.MinSupported.Version(),
},
},
},
}
var (
ctx = context.Background()
tc = testcluster.StartTestCluster(t, 1, clusterArgs)
conn = tc.ServerConn(0)
sqlDB = sqlutils.MakeSQLRunner(conn)
)
defer tc.Stopper().Stop(ctx)
v := clusterversion.Latest.Version().String()
// Check that the builtin returns false when comparing against the new
// version because we are still on the bootstrap version.
sqlDB.CheckQueryResults(t, "SELECT crdb_internal.is_at_least_version('"+v+"')", [][]string{{"false"}})
sqlDB.CheckQueryResults(t, "SELECT crdb_internal.release_series(version) FROM [SHOW CLUSTER SETTING version]",
[][]string{{clusterversion.MinSupported.ReleaseSeries().String()}})
// Run the upgrade.
sqlDB.Exec(t, "SET CLUSTER SETTING version = $1", v)
// It should now return true.
sqlDB.CheckQueryResultsRetry(t, "SELECT crdb_internal.is_at_least_version('"+v+"')", [][]string{{"true"}})
sqlDB.CheckQueryResults(t, "SELECT crdb_internal.release_series(version) FROM [SHOW CLUSTER SETTING version]",
[][]string{{clusterversion.Latest.ReleaseSeries().String()}})
}