-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb_modes_test.sh
executable file
·101 lines (90 loc) · 2.59 KB
/
db_modes_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# This test is intended to verify that switching between DB modes "just works". Addtionally
# it tries to make sure the dirty bit behaves as expected even in heap mode.
set -euo pipefail
VERBOSE=0
TEST_LOCKED_MODE=0
while getopts ":lv" opt; do
case ${opt} in
l)
TEST_LOCKED_MODE=1
;;
v)
VERBOSE=1
set -o xtrace
;;
\?)
echo "Use -v for verbose; -l to enable test of locked mode"
exit 1;
;;
:)
echo "Invalid option"
exit 1;
;;
esac
done
EOSIO_STUFF_DIR=$(mktemp -d)
trap "rm -rf $EOSIO_STUFF_DIR" EXIT
NODEOS_LAUNCH_PARAMS="./programs/nodeos/nodeos -d $EOSIO_STUFF_DIR --config-dir $EOSIO_STUFF_DIR \
--chain-state-db-size-mb 8 --chain-state-db-guard-size-mb 0 --reversible-blocks-db-size-mb 1 \
--reversible-blocks-db-guard-size-mb 0 -e -peosio"
run_nodeos() {
if (( $VERBOSE == 0 )); then
$NODEOS_LAUNCH_PARAMS --http-server-address '' --p2p-listen-endpoint '' "$@" 2>/dev/null &
else
$NODEOS_LAUNCH_PARAMS --http-server-address '' --p2p-listen-endpoint '' "$@" &
fi
}
run_expect_success() {
run_nodeos "$@"
local NODEOS_PID=$!
sleep 10
kill $NODEOS_PID
wait $NODEOS_PID
}
run_and_kill() {
run_nodeos "$@"
local NODEOS_PID=$!
sleep 10
kill -KILL $NODEOS_PID
! wait $NODEOS_PID
}
run_expect_failure() {
run_nodeos "$@"
local NODEOS_PID=$!
MYPID=$$
(sleep 20; kill -ALRM $MYPID) & local TIMER_PID=$!
trap "kill $NODEOS_PID; wait $NODEOS_PID; exit 1" ALRM
sleep 10
if wait $NODEOS_PID; then exit 1; fi
kill $TIMER_PID
trap ALRM
}
#new chain with mapped mode
run_expect_success --delete-all-blocks
#use previous DB with heap mode
run_expect_success --database-map-mode heap
#test lock mode if enabled
if (( $TEST_LOCKED_MODE == 1 )); then
run_expect_success --database-map-mode locked
fi
#locked mode should fail when it's not possible to lock anything
ulimit -l 0
run_expect_failure --database-map-mode locked
#But shouldn't result in the dirty flag staying set; so next launch should run
run_expect_success
#Try killing with KILL
run_and_kill
#should be dirty now
run_expect_failure
#should also still be dirty in heap mode
run_expect_failure --database-map-mode heap
#start over again! but this time start with heap mode
run_expect_success --delete-all-blocks --database-map-mode heap
#Then switch back to mapped
run_expect_success
#try killing it while in heap mode
run_and_kill --database-map-mode heap
#should be dirty if we run in either mode node
run_expect_failure --database-map-mode heap
run_expect_failure