1+ #! /bin/bash
2+
3+ set -e
4+
5+ # Setup separate workspace directories
6+ mkdir -p /tmp/protoplaster/node1/{tests,reports,artifacts}
7+ mkdir -p /tmp/protoplaster/node2/{tests,reports,artifacts}
8+ mkdir -p /tmp/protoplaster/main/{tests,reports,artifacts}
9+
10+ # Create a local output directory for this script's results
11+ OUTPUT_DIR=" test_output"
12+ mkdir -p " $OUTPUT_DIR "
13+
14+ # Create devices.yaml for the main node
15+ cat << EOF > /tmp/protoplaster/devices.yaml
16+ node1: localhost:2138
17+ node2: localhost:2139
18+ EOF
19+
20+ # Create the multinode test config
21+ cat << EOF > /tmp/protoplaster/api-test-multinode-simple.yml
22+ tests:
23+ local_tests:
24+ - simple:
25+ device: "local_dev"
26+ node1_tests:
27+ - simple:
28+ device: "node1_dev"
29+ machines: [node1]
30+ node2_tests:
31+ - simple:
32+ device: "node2_dev"
33+ machines: [node2]
34+ EOF
35+
36+ echo " Starting Protoplaster nodes..."
37+
38+ # Start Worker Node 1
39+ protoplaster --test-dir /tmp/protoplaster/node1/tests \
40+ --reports-dir /tmp/protoplaster/node1/reports \
41+ --artifacts-dir /tmp/protoplaster/node1/artifacts \
42+ --port 2138 --server &
43+ PID1=$!
44+
45+ # Start Worker Node 2
46+ protoplaster --test-dir /tmp/protoplaster/node2/tests \
47+ --reports-dir /tmp/protoplaster/node2/reports \
48+ --artifacts-dir /tmp/protoplaster/node2/artifacts \
49+ --port 2139 --server &
50+ PID2=$!
51+
52+ # Start Main Node
53+ protoplaster --test-dir /tmp/protoplaster/main/tests \
54+ --reports-dir /tmp/protoplaster/main/reports \
55+ --artifacts-dir /tmp/protoplaster/main/artifacts \
56+ --external-devices /tmp/protoplaster/devices.yaml \
57+ --port 5000 --server &
58+ PID_MAIN=$!
59+
60+ # Cleanup function
61+ function finish {
62+ echo " Stopping servers..."
63+ kill $PID1 $PID2 $PID_MAIN 2> /dev/null || true
64+ }
65+ trap finish EXIT
66+
67+ # Wait for servers
68+ echo " Waiting for servers to start..."
69+ for port in 2138 2139 5000; do
70+ while ! curl -s http://localhost:$port /api/v1/configs > /dev/null; do
71+ sleep 1
72+ done
73+ done
74+
75+ # Upload config to ALL nodes
76+ CONFIG_FILE=" api-test-multinode-simple.yml"
77+ for port in 2138 2139 5000; do
78+ echo " Uploading config to port $port ..."
79+ NAME=$( curl -s -X POST http://localhost:$port /api/v1/configs -F " file=@/tmp/protoplaster/$CONFIG_FILE " | jq -r ' .name' )
80+ if [ " $NAME " != " $CONFIG_FILE " ] ; then
81+ echo " Config upload failed on port $port !"
82+ exit 1
83+ fi
84+ done
85+
86+ # Trigger test run on Main Node
87+ echo " Triggering run on Main Node..."
88+ MAIN_RUN_ID=$( curl -s -X POST http://localhost:5000/api/v1/test-runs \
89+ -H " Content-Type: application/json" \
90+ -d " {\" config_name\" : \" $CONFIG_FILE \" }" | jq -r ' .id' )
91+
92+ echo " Main Run ID: $MAIN_RUN_ID "
93+
94+ verify_node_execution () {
95+ local port=$1
96+ local node_name=$2
97+
98+ # Define file paths inside output directory
99+ local report_file=" $OUTPUT_DIR /${node_name} _report.csv"
100+ local artifact_file=" $OUTPUT_DIR /${node_name} _file.txt"
101+
102+ # Get the latest run ID for this node
103+ local run_id=$( curl -s http://localhost:$port /api/v1/test-runs | jq -r ' .[-1].id' )
104+
105+ echo " Verifying $node_name (Port $port , Run ID: $run_id )..."
106+
107+ # Wait for finish
108+ local status=" "
109+ while [ " $status " != " finished" ] && [ " $status " != " failed" ]; do
110+ status=$( curl -s http://localhost:$port /api/v1/test-runs/$run_id | jq -r ' .status' )
111+ sleep 1
112+ done
113+
114+ # Get report and save to output dir
115+ curl -s http://localhost:$port /api/v1/test-runs/$run_id /report > " $report_file "
116+
117+ # Verify specific device test ran
118+ if ! grep -q " simple" " $report_file " ; then
119+ echo " FAILURE: $node_name report does not contain expected string"
120+ exit 1
121+ fi
122+
123+ # Verify TestSimple::test_success PASSED
124+ local success_status=$( grep ' TestSimple::test_success' " $report_file " | cut -d ' ,' -f6)
125+ if [ " $success_status " != " passed" ]; then
126+ echo " FAILURE: $node_name test_success did not pass! Status: $success_status "
127+ exit 1
128+ fi
129+
130+ # Verify TestSimple::test_failure FAILED
131+ local fail_status=$( grep ' TestSimple::test_failure' " $report_file " | cut -d ' ,' -f6)
132+ if [ " $fail_status " != " failed" ]; then
133+ echo " FAILURE: $node_name test_failure did not fail! Status: $fail_status "
134+ exit 1
135+ fi
136+
137+ # Verify artifact recorded
138+ local artifacts_entry=$( grep ' TestSimple::test_record_artifact' " $report_file " | cut -d ' ,' -f7-)
139+ if ! echo " $artifacts_entry " | grep -q " file.txt" ; then
140+ echo " FAILURE: $node_name did not record 'file.txt' artifact in report!"
141+ exit 1
142+ fi
143+
144+ # Download and verify artifact content
145+ curl -s " http://localhost:$port /api/v1/test-runs/$run_id /artifacts/file.txt" > " $artifact_file "
146+ if [ " $( cat " $artifact_file " ) " != " test" ]; then
147+ echo " FAILURE: $node_name artifact content mismatch!"
148+ exit 1
149+ fi
150+
151+ echo " SUCCESS: $node_name verified."
152+ }
153+
154+ # Verify all nodes
155+ verify_node_execution 5000 " MainNode"
156+ verify_node_execution 2138 " Node1"
157+ verify_node_execution 2139 " Node2"
158+
159+ echo " ---------------------------------------------------"
160+ echo " Multinode Simple Test: ALL CHECKS PASSED"
161+ echo " Results saved in: $OUTPUT_DIR "
162+ echo " ---------------------------------------------------"
0 commit comments