blob: deb0a5466d75b3fb7461996eab760bc98854a8b9 (
plain)
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
102
103
104
105
106
107
|
#!/usr/bin/expect -f
#exp_internal 1
set err 0
log_user 1
if { [catch {
source goalExpectCommon.exp
set TEST_ALGO_DIR [lindex $argv 0]
set TEST_DATA_DIR [lindex $argv 1]
puts "TEST_ALGO_DIR: $TEST_ALGO_DIR"
puts "TEST_DATA_DIR: $TEST_DATA_DIR"
set TIME_STAMP [clock seconds]
set TEST_ROOT_DIR $TEST_ALGO_DIR/root
set TEST_PRIMARY_NODE_DIR $TEST_ROOT_DIR/Primary/
set NETWORK_NAME test_net_expect_$TIME_STAMP
set NETWORK_TEMPLATE "$TEST_DATA_DIR/nettemplates/TwoNodes50Each.json"
# Create network
::AlgorandGoal::CreateNetwork $NETWORK_NAME $NETWORK_TEMPLATE $TEST_ALGO_DIR $TEST_ROOT_DIR
# Start network
::AlgorandGoal::StartNetwork $NETWORK_NAME $NETWORK_TEMPLATE $TEST_ROOT_DIR
exec sleep 5
# Start node
::AlgorandGoal::StartNode $TEST_PRIMARY_NODE_DIR
# Try starting the node again, should just report the node is already running
set ALREADY_STARTED_MESSAGE_RECEIVED 0
spawn goal node start -d $TEST_PRIMARY_NODE_DIR
expect {
timeout { close; ::AlgorandGoal::Abort "goal node start unexpectedly failed" }
"^Algorand node was already started!" {
set ALREADY_STARTED_MESSAGE_RECEIVED 1
exp_continue
}
-re "\\S+" { close; ::AlgorandGoal::Abort "Unexpected message for goal node start on a running node" }
eof {
if {$ALREADY_STARTED_MESSAGE_RECEIVED == 0} {
{ close; ::AlgorandGoal::Abort "eof received before the expected message "}
}
}
}
# Restart node
::AlgorandGoal::RestartNode $TEST_PRIMARY_NODE_DIR
# Stop node
::AlgorandGoal::StopNode $TEST_PRIMARY_NODE_DIR
# Try stopping the node again, should fail
spawn goal node stop -d $TEST_PRIMARY_NODE_DIR
expect {
timeout { close; ::AlgorandGoal::Abort "Goal Node Stop did not fail as expected" }
"^Cannot kill node: no running node in directory '*'" {puts "Node failed successfully"; close}
eof { close; ::AlgorandGoal::Abort "Goal Node Stop did not fail as expected" }
}
#Try stopping node in invalid directory, should fail
spawn goal node stop -d ''
expect {
timeout { close; ::AlgorandGoal::Abort "Goal Node Fail did not fail as expected" }
"^Cannot kill node: the provided directory '*' does not exist" {puts "Node failed successfully"; close}
eof { close; ::AlgorandGoal::Abort "Goal Node Stop did not fail as expected" }
}
# "break" the node by replacing it's ledger data files with "broken" ones.
lassign [exec find $TEST_PRIMARY_NODE_DIR -name "ledger.tracker.sqlite"] PRIMARY_TRACKER_DATABASE_FILE
exec find $TEST_PRIMARY_NODE_DIR -name "ledger.tracker.sqlite*" -delete
exec -- echo "1234" > $PRIMARY_TRACKER_DATABASE_FILE
# try to start the primary node, and observe the expected failure
set timeout 15
spawn goal node start -d $TEST_PRIMARY_NODE_DIR
expect {
timeout { close; ::AlgorandGoal::Abort "starting node exceeded timeout" }
-re {^Algorand node failed to start: node exited with an error code, check node\.log for more details : exit status 1} {
puts "\nExpected failuire : node failed to start"
# wait until the eof signal is received
expect {
timeout { close; ::AlgorandGoal::Abort "failed to see node terminating after outputing error message" }
eof { puts "eof received as expected after error message output" }
}
}
eof { ::AlgorandGoal::Abort "eof received before the expected output " }
}
lassign [::AlgorandGoal::CheckProcessReturnedCode 0] response OS_CODE ERROR_CODE KILLED KILL_SIGNAL EXP
if {$ERROR_CODE != 1} {
puts "Node was expected to fail with 1 due to invalid ledger file, but returned error code $ERROR_CODE instead"
exit 1
}
# Shutdown the network
::AlgorandGoal::StopNetwork $NETWORK_NAME $TEST_ROOT_DIR
puts "Basic Goal Test Successful"
exit 0
} EXCEPTION] } {
puts "ERROR in goalNodeTest: $EXCEPTION"
exit 1
}
|