github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/cli/interactive_tests/test_reconnect.tcl (about)

     1  #! /usr/bin/env expect -f
     2  
     3  source [file join [file dirname $argv0] common.tcl]
     4  
     5  start_server $argv
     6  
     7  spawn $argv sql
     8  eexpect root@
     9  
    10  start_test "Test initialization"
    11  send "create database t; set database = t;\r"
    12  eexpect root@
    13  eexpect "/t>"
    14  
    15  send "select 1;\r"
    16  eexpect "1 row"
    17  eexpect root@
    18  end_test
    19  
    20  start_test "Check that the client properly detects the server went down"
    21  # We need to force since the open connection may prevent a quick
    22  # graceful shutdown.
    23  force_stop_server $argv
    24  
    25  send "select 1;\r"
    26  eexpect "bad connection"
    27  eexpect root@
    28  eexpect " ?>"
    29  end_test
    30  
    31  start_test "Check that the client gracefully fails to reconnect"
    32  send "select 1;\r"
    33  eexpect "opening new connection"
    34  expect {
    35      "connection refused" {}
    36      "connection reset by peer" {}
    37      timeout { handle_timeout "connection error" }
    38  }
    39  eexpect root@
    40  eexpect " ?>"
    41  end_test
    42  
    43  start_test "Check that the client automatically reconnects when the server goes up again"
    44  start_server $argv
    45  
    46  send "select 1;\r"
    47  eexpect "opening new connection"
    48  eexpect "1 row"
    49  eexpect root@
    50  # also check that the current db is restored
    51  eexpect "/t>"
    52  end_test
    53  
    54  start_test "Check that the client picks up when the server was restarted"
    55  stop_server $argv
    56  start_server $argv
    57  
    58  send "select 1;\r"
    59  eexpect "bad connection"
    60  eexpect root@
    61  
    62  send "select 1;\r"
    63  eexpect "1 row"
    64  eexpect root@
    65  eexpect "/t>"
    66  end_test
    67  
    68  send "\\q\r"
    69  eexpect eof
    70  
    71  stop_server $argv