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

     1  #! /usr/bin/env expect -f
     2  
     3  # disabled until #48413 is resolved.
     4  
     5  source [file join [file dirname $argv0] common.tcl]
     6  
     7  spawn /bin/bash
     8  send "PS1=':''/# '\r"
     9  eexpect ":/# "
    10  
    11  start_test "Check that a server encountering a fatal error when not logging to stderr shows the fatal error."
    12  send "$argv start-single-node -s=path=logs/db --insecure\r"
    13  eexpect "CockroachDB node starting"
    14  system "$argv sql --insecure -e \"select crdb_internal.force_log_fatal('helloworld')\" || true"
    15  eexpect "\r\nF"
    16  eexpect "helloworld"
    17  eexpect ":/# "
    18  send "echo \$?\r"
    19  eexpect "255"
    20  eexpect ":/# "
    21  end_test
    22  
    23  start_test "Check that a broken stderr prints a message to the log files."
    24  # We use --log-file-max-size to avoid rotations during the test.
    25  send "$argv start-single-node -s=path=logs/db --log-file-max-size=100M --insecure --logtostderr --vmodule=*=1 2>&1 | cat\r"
    26  eexpect "CockroachDB node starting"
    27  system "killall cat"
    28  eexpect ":/# "
    29  # NB: we can't just grep for the broken pipe output, because it may take
    30  # a while for the server to initiate the next log line where it will detect
    31  # the broken pipe error.
    32  #
    33  # We use -F and not -f because the log file may be rotated during the test.
    34  #
    35  # We also watch all the log files in the directory, because the error
    36  # is only reported on the logger which is writing first after stderr
    37  # is has been broken, and that may be the secondary logger.
    38  send "tail -F `find logs/db/logs -type l`\r"
    39  eexpect "log: exiting because of error: write /dev/stderr: broken pipe"
    40  interrupt
    41  eexpect ":/# "
    42  end_test
    43  
    44  start_test "Check that a broken log file prints a message to stderr."
    45  # The path that we pass to the --log-dir will already exist as a file.
    46  system "mkdir -p logs"
    47  system "touch logs/broken"
    48  send "$argv start-single-node -s=path=logs/db --log-dir=logs/broken --insecure --logtostderr\r"
    49  eexpect "unable to create log directory"
    50  eexpect ":/# "
    51  end_test
    52  
    53  start_test "Check that a server started with only in-memory stores and no --log-dir automatically logs to stderr."
    54  send "$argv start-single-node --insecure --store=type=mem,size=1GiB\r"
    55  eexpect "CockroachDB node starting"
    56  end_test
    57  
    58  # Stop it.
    59  interrupt
    60  eexpect ":/# "
    61  
    62  # Disable replication so as to avoid spurious purgatory errors.
    63  start_server $argv
    64  send "$argv sql --insecure -e \"ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1\"\r"
    65  eexpect "CONFIGURE ZONE 1"
    66  eexpect ":/# "
    67  stop_server $argv
    68  
    69  start_test "Check that a server started with --logtostderr logs even info messages to stderr."
    70  send "$argv start-single-node -s=path=logs/db --insecure --logtostderr\r"
    71  eexpect "CockroachDB node starting"
    72  end_test
    73  
    74  # Stop it.
    75  interrupt
    76  eexpect ":/# "
    77  
    78  start_test "Check that --logtostderr can override the threshold but no error is printed on startup"
    79  send "echo marker; $argv start-single-node -s=path=logs/db --insecure --logtostderr=ERROR 2>&1 | grep -v '^\\*'\r"
    80  eexpect "marker\r\nCockroachDB node starting"
    81  end_test
    82  
    83  # Stop it.
    84  interrupt
    85  eexpect ":/# "
    86  
    87  start_test "Check that panic reports are printed to the log even when --logtostderr is specified"
    88  send "$argv start-single-node -s=path=logs/db --insecure --logtostderr\r"
    89  eexpect "CockroachDB node starting"
    90  
    91  system "($argv sql --insecure -e \"select crdb_internal.force_panic('helloworld')\" || true)&"
    92  # Check the panic is reported on the server's stderr
    93  eexpect "a SQL panic has occurred"
    94  eexpect "panic: helloworld"
    95  eexpect "goroutine"
    96  eexpect ":/# "
    97  # Check the panic is reported on the server log file
    98  send "cat logs/db/logs/cockroach.log\r"
    99  eexpect "a SQL panic has occurred"
   100  eexpect "helloworld"
   101  eexpect "a panic has occurred"
   102  eexpect "goroutine"
   103  eexpect ":/# "
   104  
   105  end_test
   106  
   107  
   108  
   109  start_server $argv
   110  
   111  start_test "Test that quit does not show INFO by default with --logtostderr"
   112  # Test quit as non-start command, this time with --logtostderr. Test
   113  # that the default logging level is WARNING, so that no INFO messages
   114  # are printed between the marker and the (first line) error message
   115  # from quit. Quit will error out because the server is already stopped.
   116  send "echo marker; $argv quit --logtostderr 2>&1 | grep -vE '^\[WEF\]\[0-9\]+|^node is draining'\r"
   117  eexpect "marker\r\nok"
   118  eexpect ":/# "
   119  end_test
   120  
   121  start_test "Check that `--logtostderr` can override the default"
   122  send "$argv quit --logtostderr=INFO --vmodule=stopper=1\r"
   123  eexpect "stop has been called"
   124  eexpect ":/# "
   125  end_test
   126  
   127  send "exit\r"
   128  eexpect eof