Skip to content

Commit

Permalink
Add bats test for graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Jul 12, 2023
1 parent d5b2ded commit 75514fa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion util/app-config/src/tests/ckb_run_replay.bats
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function ckb_run { #@test
run _ckb_run
[ "$status" -eq 0 ]
# assert_output --regexp "ckb_chain::chain.*block number:.*, hash:.*, size:.*, cycles:.*"
assert_output --regexp "ckb_bin all tokio tasks have been stopped"
assert_output --regexp "ckb_bin ckb shutdown"
}

function ckb_replay { #@test
Expand Down
4 changes: 2 additions & 2 deletions util/app-config/src/tests/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bash ${CKB_BATS_CORE_DIR}/bats-assert/load.bash

cd ${CKB_BATS_TESTBED}

./ckb init --force && ./ckb import ckb_mainnet_4000.json
./ckb init --force && sed -i 's/filter = "info"/filter = "debug"/g' ckb.toml && ./ckb import ckb_mainnet_4000.json

export PATH=${CKB_BATS_TESTBED}:/tmp/ckb_bats_bin/tmp_install/bin:${PATH}
export BATS_LIB_PATH=${CKB_BATS_CORE_DIR}
Expand All @@ -47,7 +47,7 @@ export TMP_DIR=${CKB_BATS_TESTBED}/tmp_dir
mkdir ${TMP_DIR}

for bats_cases in *.bats; do
bats --trace "$bats_cases"
bats "$bats_cases"
ret=$?
if [ "$ret" -ne "0" ]; then
exit "$ret"
Expand Down
45 changes: 45 additions & 0 deletions util/app-config/src/tests/graceful_shutdown.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bats
bats_load_library 'bats-assert'
bats_load_library 'bats-support'

_ckb_graceful_shutdown() {
ckb run -C ${CKB_DIRNAME} &> ${TMP_DIR}/ckb_run.log &
PID=$!
sleep 10
kill ${PID}

while kill -0 ${PID}; do
echo "waiting for ckb to exit"
sleep 1
done

tail -n 500 ${TMP_DIR}/ckb_run.log
}

function ckb_graceful_shutdown { #@test
run _ckb_graceful_shutdown

[ "$status" -eq 0 ]
assert_output --regexp "INFO ckb_bin::subcommand::run Trapped exit signal, exiting..."
assert_output --regexp "DEBUG ckb_stop_handler::stop_register received exit signal, broadcasting exit signal to all threads"
assert_output --regexp "DEBUG ckb_tx_pool::chunk_process TxPool received exit signal, exit now"
assert_output --regexp "DEBUG ckb_sync::types::header_map HeaderMap limit_memory received exit signal, exit now"
assert_output --regexp "DEBUG ckb_chain::chain ChainService received exit signal, exit now"
assert_output --regexp "DEBUG ckb_sync::synchronizer thread BlockDownload received exit signal, exit now"
assert_output --regexp "DEBUG ckb_network::network NetworkService receive exit signal, start shutdown..."
assert_output --regexp "INFO ckb_tx_pool::service TxPool is saving, please wait..."
assert_output --regexp "DEBUG ckb_tx_pool::service TxPool received exit signal, exit now"
assert_output --regexp "DEBUG ckb_block_filter::filter BlockFilter received exit signal, exit now"
assert_output --regexp "DEBUG ckb_network::services::dump_peer_store dump peer store before exit"
assert_output --regexp "DEBUG ckb_notify NotifyService received exit signal, exit now"
assert_output --regexp "DEBUG ckb_stop_handler::stop_register wait thread ChainService done"
assert_output --regexp "DEBUG ckb_stop_handler::stop_register wait thread BlockDownload done"
assert_output --regexp "DEBUG ckb_stop_handler::stop_register all ckb threads have been stopped"
assert_output --regexp "DEBUG ckb_bin waiting all tokio tasks done"
assert_output --regexp "INFO ckb_tx_pool::process TxPool save successfully"
assert_output --regexp "INFO ckb_bin ckb shutdown"
}

teardown_file() {
rm -f ${TMP_DIR}/ckb_run.log
}

0 comments on commit 75514fa

Please sign in to comment.