Skip to content

Commit 89e1b5a

Browse files
craig[bot]rafiss
andcommitted
Merge #149783
149783: cli: unskip test_demo_multitenant r=rafiss a=rafiss This applies the same fix that was made for test_demo_node_cmds in 015b29c. To check the liveness range, the test needs to switch to the system tenant, so a new shorthand was added for that. We also specify the demo password deterministically so that we can switch connections. fixes #141942 Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents 22f815b + 6695a01 commit 89e1b5a

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

pkg/acceptance/generated_cli_test.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/clisqlshell/sql.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Connection
6666
connect to a server or print the current connection URL.
6767
Omitted values reuse previous parameters. Use '-' to skip a field.
6868
The option "autocerts" attempts to auto-discover TLS client certs.
69+
The option "tenant=NAME" switches to the specified tenant.
6970
\password [USERNAME]
7071
securely change the password for a user
7172
@@ -1708,6 +1709,11 @@ func (c *cliState) handleConnectInternal(cmd []string, omitConnString bool) erro
17081709
if cmd[4] != "-" {
17091710
if cmd[4] == "autocerts" {
17101711
autoCerts = true
1712+
} else if strings.HasPrefix(cmd[4], "tenant=") {
1713+
tenantName := strings.TrimPrefix(cmd[4], "tenant=")
1714+
if err := newURL.SetOption("options", "-ccluster="+tenantName); err != nil {
1715+
return err
1716+
}
17111717
} else {
17121718
return errors.Newf(`unknown syntax: \c %s`, strings.Join(cmd, " "))
17131719
}

pkg/cli/interactive_tests/test_demo_multitenant.tcl.disabled renamed to pkg/cli/interactive_tests/test_demo_multitenant.tcl

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#! /usr/bin/env expect -f
22

3-
# TODO(141942): Re-enable this test once we have investigated its flakiness.
4-
53
source [file join [file dirname $argv0] common.tcl]
64

7-
spawn $argv demo --no-line-editor --empty --nodes 3 --multitenant --log-dir=logs
5+
set ::env(COCKROACH_DEMO_PASSWORD) "hunter2hunter2hunter2hunter2"
6+
7+
spawn $argv demo --no-line-editor --empty --nodes 5 --multitenant --log-dir=logs
88

99
start_test "Check that the demo cluster starts properly"
1010
eexpect "Welcome"
@@ -43,31 +43,67 @@ eexpect "defaultdb>"
4343
end_test
4444

4545
start_test "Check that the demo add command adds a node with no error in ls"
46-
send "\\demo add region=us-east-1\r"
47-
eexpect "node 4 has been added"
46+
send "\\demo add region=us-west1\r"
47+
eexpect "node 6 has been added"
4848
eexpect "defaultdb>"
4949
send "\\demo ls\r"
5050
eexpect "node 1:"
5151
eexpect "node 2:"
5252
eexpect "node 3:"
5353
eexpect "node 4:"
54+
eexpect "node 5:"
55+
eexpect "node 6:"
5456
eexpect "Application tenant:"
5557
eexpect "System tenant:"
5658
eexpect "defaultdb>"
5759
end_test
5860

5961
start_test "Check that a node can be restarted"
60-
send "\\demo shutdown 4\r"
61-
eexpect "node 4 has been shutdown"
62+
63+
# Switch to system tenant to check the liveness range.
64+
send "\\connect - - - - tenant=system\r"
65+
eexpect "the cluster ID has changed!"
66+
eexpect "defaultdb>"
67+
68+
# Wait for the liveness range to have the default 5 voters. If its replication
69+
# factor is too low, shutting down the node below can cause it to lose quorum
70+
# and stall the shutdown command (example: #147867).
71+
set timeout 2
72+
set stmt "select range_id, array_length(voting_replicas,1) from crdb_internal.ranges where range_id=2;\r"
73+
send $stmt
74+
expect {
75+
"2 | 5" {
76+
puts "\rliveness range has 5 voters"
77+
}
78+
timeout {
79+
puts "\rliveness range does not yet have 5 voters"
80+
sleep 2
81+
send $stmt
82+
exp_continue
83+
}
84+
}
85+
# Reset timeout back to 45 to match common.tcl.
86+
set timeout 45
87+
eexpect "defaultdb>"
88+
89+
# Switch back to application tenant for the rest of the test.
90+
send "\\connect - - - - tenant=demoapp\r"
91+
eexpect "the cluster ID has changed!"
92+
eexpect "defaultdb>"
93+
94+
send "\\demo shutdown 6\r"
95+
eexpect "node 6 has been shutdown"
6296
eexpect "defaultdb>"
63-
send "\\demo restart 4\r"
64-
eexpect "node 4 has been restarted"
97+
send "\\demo restart 6\r"
98+
eexpect "node 6 has been restarted"
6599
eexpect "defaultdb>"
66100
send "\\demo ls\r"
67101
eexpect "node 1:"
68102
eexpect "node 2:"
69103
eexpect "node 3:"
70104
eexpect "node 4:"
105+
eexpect "node 5:"
106+
eexpect "node 6:"
71107
eexpect "Application tenant:"
72108
eexpect "System tenant:"
73109
eexpect "defaultdb>"

0 commit comments

Comments
 (0)