github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cli/interactive_tests/test_init_command.tcl (about) 1 #! /usr/bin/env expect -f 2 # 3 source [file join [file dirnam $argv0] common.tcl] 4 5 # Start a server with a --join flag so the init command is required 6 # (even though we have no intention of starting a second node). Note that unlike other 7 # expect-based tests, this one doesn't use a fifo for --pid_file 8 # because we don't want reads from that fifo to change the outcome. 9 system "$argv start --insecure --pid-file=server_pid -s=path=logs/db --listen-addr=localhost --background --join=localhost:26258 >>logs/expect-cmd.log 2>&1" 10 11 start_test "Check that the server has informed us and the log file that it was ready before forking off in the background" 12 system "grep -q 'initial startup completed' logs/db/logs/cockroach.log" 13 system "grep -q 'will now attempt to join a running cluster, or wait' logs/db/logs/cockroach.log" 14 end_test 15 16 start_test "Check that the SQL shell successfully times out upon connecting to an uninitialized node" 17 # We shorten the default timeout of 5 seconds to make this test run faster. 18 set ::env(COCKROACH_CONNECT_TIMEOUT) "1" 19 spawn /bin/bash 20 send "PS1=':''/# '\r" 21 eexpect ":/# " 22 send "$argv sql\r" 23 eexpect "ERROR: cannot dial server" 24 send "exit\r" 25 eexpect eof 26 end_test 27 28 # The following tests expect the client to wait forever. 29 set ::env(COCKROACH_CONNECT_TIMEOUT) "0" 30 31 start_test "Check that init allows a suspended SQL client to resume" 32 33 # Start a shell and send a command. The shell should block at startup, 34 # so we don't "expect" anything yet. The point of this test is to 35 # verify that the command will succeed after blocking instead of 36 # erroring out. 37 spawn $argv sql 38 send "show tables from system.pg_catalog;\r" 39 40 # Now initialize the one-node cluster. This will unblock the pending 41 # SQL connection. This also verifies that the blocked connection using 42 # the pgwire listener does not block the grpc listener used for the 43 # init command. 44 system "$argv init --insecure --host=localhost" 45 46 # The command should now succeed, without logging any errors or 47 # warnings. 48 expect { 49 "pg_class" {} 50 # Hopefully this broad regex will match any errors we log 51 # (Currently, everything I've seen begins with "ERROR:") 52 -re "(?i)err" { 53 set prefix $expect_out(buffer) 54 # Read next line to finish the error message. 55 # TODO(bdarnell): Surely there's a smarter way to do this. 56 expect "\n" 57 report "ERROR LOGGED:\n$prefix$expect_out(buffer)" 58 exit 1 59 } 60 timeout { handle_timeout "pg_class" } 61 } 62 63 interrupt 64 interrupt 65 eexpect eof 66 67 end_test 68 69 spawn /bin/bash 70 send "PS1=':''/# '\r" 71 eexpect ":/# " 72 73 start_test "Check that init on an already started server immediately complains the server is already initialized" 74 send "$argv init --insecure --host=localhost\r" 75 eexpect "error" 76 eexpect "cluster has already been initialized" 77 eexpect ":/# " 78 end_test 79 80 stop_server $argv 81 start_server $argv 82 83 start_test "Check that init after server restart still properly complains the server has been initialized" 84 send "$argv init --insecure --host=localhost\r" 85 eexpect "error" 86 eexpect "cluster has already been initialized" 87 eexpect ":/# " 88 end_test 89 90 send "exit 0\r" 91 eexpect eof 92 93 stop_server $argv