-
Notifications
You must be signed in to change notification settings - Fork 28
224 lines (182 loc) · 6.84 KB
/
example-app-test.yml
File metadata and controls
224 lines (182 loc) · 6.84 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Example App Test
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
example-app-test:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Check out repo
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run full flow
shell: bash
run: |
set -Eeuo pipefail
SERVER_PID=""
CAMERA_PID=""
APP1_PID=""
APP2_PID=""
cleanup() {
echo "Cleaning up background processes..."
for pid in "$APP2_PID" "$APP1_PID" "$CAMERA_PID" "$SERVER_PID"; do
if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then
kill "${pid}" 2>/dev/null || true
fi
done
sleep 2
for pid in "$APP2_PID" "$APP1_PID" "$CAMERA_PID" "$SERVER_PID"; do
if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then
kill -9 "${pid}" 2>/dev/null || true
fi
done
}
trap cleanup EXIT
echo "=== Step 1: Generate credentials and camera secret ==="
pushd config_tool
cargo run --release -- --generate-camera-secret --dir camera_secret
test -f camera_secret/camera_secret
cargo run --release -- --generate-user-credentials --server-addr http://127.0.0.1:8000 --dir credentials
test -f credentials/user_credentials
test -f credentials/user_credentials_for_testing
popd
mkdir -p server/user_credentials
cp config_tool/camera_secret/camera_secret camera_hub/
cp config_tool/camera_secret/camera_secret app_native/
cp config_tool/credentials/user_credentials_for_testing app_native/user_credentials
cp config_tool/credentials/user_credentials server/user_credentials/
echo "=== Step 2: Launch server ==="
pushd server
cargo build --release
SECLUSO_SKIP_FCM_CONFIG=1 cargo run --release > server.log 2>&1 &
SERVER_PID=$!
popd
echo "Server PID: ${SERVER_PID}"
echo "Waiting for server to listen on 127.0.0.1:8000 ..."
while true; do
if bash -c 'echo > /dev/tcp/127.0.0.1/8000' >/dev/null 2>&1; then
echo "Server is up."
break
fi
if ! kill -0 "${SERVER_PID}" 2>/dev/null; then
echo "Server exited before becoming ready."
cat server/server.log || true
exit 1
fi
sleep 1
done
echo "=== Step 3: Launch camera ==="
pushd camera_hub
rm -rf state pending_*
cargo build --release --features test
RUST_LOG=error cargo run --release --features test > camera.log 2>&1 &
CAMERA_PID=$!
popd
echo "Camera PID: ${CAMERA_PID}"
sleep 5
if ! kill -0 "${CAMERA_PID}" 2>/dev/null; then
echo "Camera exited unexpectedly."
echo "Server log:"
cat server/server.log || true
echo "Camera log:"
cat camera_hub/camera.log || true
exit 1
fi
echo "=== Step 4: Launch first app ==="
pushd app_native
rm -rf example_app_data
cargo build --release --example app --features for-example
RUST_BACKTRACE=1 RUST_LOG=error cargo run --release --example app --features for-example > app1.log 2>&1 &
APP1_PID=$!
popd
echo "App 1 PID: ${APP1_PID}"
echo "Waiting 10 seconds before launching second app..."
sleep 10
if ! kill -0 "${APP1_PID}" 2>/dev/null; then
echo "First app exited before second app launch."
wait "${APP1_PID}" || true
echo "Server log:"
cat server/server.log || true
echo "Camera log:"
cat camera_hub/camera.log || true
echo "App1 log:"
cat app_native/app1.log || true
exit 1
fi
echo "=== Step 5: Launch second app ==="
rm -rf app_native_2
mkdir -p app_native_2
cp app_native/target/release/examples/app app_native_2/app
cp app_native/user_credentials app_native_2/
pushd app_native_2
rm -rf example_app_data
chmod +x ./app
RUST_LOG=error ./app --secondary-app > app2.log 2>&1 &
APP2_PID=$!
popd
echo "App 2 PID: ${APP2_PID}"
echo "=== Monitoring both apps ==="
APP1_STATUS=""
APP2_STATUS=""
while true; do
if [[ -z "${APP1_STATUS}" ]] && ! kill -0 "${APP1_PID}" 2>/dev/null; then
set +e
wait "${APP1_PID}"
APP1_STATUS=$?
set -e
echo "App 1 exited with status ${APP1_STATUS}"
fi
if [[ -z "${APP2_STATUS}" ]] && ! kill -0 "${APP2_PID}" 2>/dev/null; then
set +e
wait "${APP2_PID}"
APP2_STATUS=$?
set -e
echo "App 2 exited with status ${APP2_STATUS}"
fi
if [[ -n "${APP1_STATUS}" && "${APP1_STATUS}" != "0" ]]; then
echo "App 1 failed."
echo "--- app1.log ---"
cat app_native/app1.log || true
echo "--- app2.log ---"
cat app_native_2/app2.log || true
echo "--- server.log ---"
cat server/server.log || true
echo "--- camera.log ---"
cat camera_hub/camera.log || true
exit 1
fi
if [[ -n "${APP2_STATUS}" && "${APP2_STATUS}" != "0" ]]; then
echo "App 2 failed."
echo "--- app1.log ---"
cat app_native/app1.log || true
echo "--- app2.log ---"
cat app_native_2/app2.log || true
echo "--- server.log ---"
cat server/server.log || true
echo "--- camera.log ---"
cat camera_hub/camera.log || true
exit 1
fi
if [[ -n "${APP1_STATUS}" && -n "${APP2_STATUS}" ]]; then
echo "Both apps exited successfully."
break
fi
if ! kill -0 "${SERVER_PID}" 2>/dev/null; then
echo "Server exited unexpectedly while apps were running."
cat server/server.log || true
exit 1
fi
if ! kill -0 "${CAMERA_PID}" 2>/dev/null; then
echo "Camera exited unexpectedly while apps were running."
cat camera_hub/camera.log || true
exit 1
fi
sleep 2
done
echo "Example app workflow completed successfully."