-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathtest_status_display.sh
More file actions
executable file
·281 lines (225 loc) · 7.95 KB
/
Copy pathtest_status_display.sh
File metadata and controls
executable file
·281 lines (225 loc) · 7.95 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/bash
# PMDaemon CLI Status Display Test Script
# This script tests all status items in the CLI UI to ensure they're working correctly
set -e
echo "🧪 PMDaemon CLI Status Display Test"
echo "=================================="
echo
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Test configuration
TEST_APP_NAME="test-status-app"
TEST_PORT=8899
# Function to print test status
print_test() {
echo -e "${BLUE}[TEST]${NC} $1"
}
print_success() {
echo -e "${GREEN}[PASS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[FAIL]${NC} $1"
}
# Function to wait for process state
wait_for_state() {
local expected_state="$1"
local timeout=10
local count=0
while [ $count -lt $timeout ]; do
if cargo run --bin pmdaemon -- list | grep -q "$expected_state"; then
return 0
fi
sleep 1
count=$((count + 1))
done
return 1
}
# Cleanup function
cleanup() {
echo
print_test "Cleaning up test processes..."
cargo run --bin pmdaemon -- delete "$TEST_APP_NAME" 2>/dev/null || true
cargo run --bin pmdaemon -- stop all 2>/dev/null || true
}
# Set trap for cleanup
trap cleanup EXIT
echo "Building PMDaemon..."
cargo build --bin pmdaemon
echo
print_test "1. Testing basic process creation and status display"
# Create a simple test process
cat > test_config.json << EOF
{
"name": "$TEST_APP_NAME",
"script": "python3",
"args": ["-c", "import time; [print(f'Test app running... {i}') or time.sleep(2) for i in range(1000)]"],
"cwd": ".",
"env": {
"TEST_ENV": "test_value"
},
"port": $TEST_PORT,
"autorestart": true,
"max_restarts": 3
}
EOF
# Start the test process
print_test "Starting test process..."
cargo run --bin pmdaemon -- start test_config.json
# Wait a moment for the process to start
sleep 2
echo
print_test "2. Checking all status fields in CLI output"
# Get the status output
STATUS_OUTPUT=$(cargo run --bin pmdaemon -- list)
echo "Current status output:"
echo "$STATUS_OUTPUT"
echo
# Test each field
print_test "Verifying status fields:"
# Check if ID field is present (should be 8 characters)
if echo "$STATUS_OUTPUT" | grep -E "[a-f0-9]{8}" > /dev/null; then
print_success "✓ ID field: Present (8-char UUID prefix)"
else
print_error "✗ ID field: Missing or invalid format"
fi
# Check if Name field is present
if echo "$STATUS_OUTPUT" | grep "$TEST_APP_NAME" > /dev/null; then
print_success "✓ Name field: Present ($TEST_APP_NAME)"
else
print_error "✗ Name field: Missing"
fi
# Check if Status field is present (should be 'online' for running process)
if echo "$STATUS_OUTPUT" | grep -E "(online|starting)" > /dev/null; then
print_success "✓ Status field: Present (online/starting)"
else
print_error "✗ Status field: Missing or unexpected value"
fi
# Check if PID field is present (should be a number)
if echo "$STATUS_OUTPUT" | grep -E "[0-9]{3,}" > /dev/null; then
print_success "✓ PID field: Present (numeric)"
else
print_error "✗ PID field: Missing or invalid"
fi
# Check if Uptime field is present (should show time format like 1s, 1m, etc.)
if echo "$STATUS_OUTPUT" | grep -E "[0-9]+[smhd]" > /dev/null; then
print_success "✓ Uptime field: Present (time format)"
else
print_warning "⚠ Uptime field: May be missing or showing '-'"
echo " Current uptime values in output:"
echo "$STATUS_OUTPUT" | awk '{print " " $5}' | tail -n +2
fi
# Check if Restarts field is present (should be 0 for new process)
if echo "$STATUS_OUTPUT" | grep -E "\s+0\s+" > /dev/null; then
print_success "✓ Restarts field: Present (showing 0 for new process)"
else
print_warning "⚠ Restarts field: May be missing or unexpected value"
fi
# Check if CPU field is present (should show percentage)
if echo "$STATUS_OUTPUT" | grep -E "[0-9]+\.[0-9]" > /dev/null; then
print_success "✓ CPU field: Present (decimal format)"
else
print_warning "⚠ CPU field: May be missing or showing 0.0"
fi
# Check if Memory field is present (should show with unit like MB, KB)
if echo "$STATUS_OUTPUT" | grep -E "[0-9]+(\.[0-9]+)?(MB|KB|GB|B)" > /dev/null; then
print_success "✓ Memory field: Present (with units)"
else
print_warning "⚠ Memory field: May be missing or showing '-'"
fi
# Check if Port field is present
if echo "$STATUS_OUTPUT" | grep "$TEST_PORT" > /dev/null; then
print_success "✓ Port field: Present ($TEST_PORT)"
else
print_warning "⚠ Port field: May be missing or showing '-'"
fi
echo
print_test "3. Testing uptime progression over time"
echo "Waiting 5 seconds to test uptime progression..."
sleep 5
STATUS_OUTPUT_2=$(cargo run --bin pmdaemon -- list)
echo "Status after 5 seconds:"
echo "$STATUS_OUTPUT_2"
# Extract uptime values
UPTIME_1=$(echo "$STATUS_OUTPUT" | grep "$TEST_APP_NAME" | awk '{print $5}' || echo "N/A")
UPTIME_2=$(echo "$STATUS_OUTPUT_2" | grep "$TEST_APP_NAME" | awk '{print $5}' || echo "N/A")
echo "Uptime comparison:"
echo " Initial: $UPTIME_1"
echo " After 5s: $UPTIME_2"
if [[ "$UPTIME_1" != "$UPTIME_2" ]] && [[ "$UPTIME_2" != "-" ]] && [[ "$UPTIME_2" != "N/A" ]]; then
print_success "✓ Uptime progression: Working (values changed)"
else
print_error "✗ Uptime progression: Not working or stuck"
fi
echo
print_test "4. Testing process restart and restart counter"
print_test "Restarting process to test restart counter..."
cargo run --bin pmdaemon -- restart "$TEST_APP_NAME"
# Wait for restart to complete
sleep 3
STATUS_OUTPUT_3=$(cargo run --bin pmdaemon -- list)
echo "Status after restart:"
echo "$STATUS_OUTPUT_3"
# Check if restart counter increased
if echo "$STATUS_OUTPUT_3" | grep "$TEST_APP_NAME" | grep -E "\s+[1-9]\s+" > /dev/null; then
print_success "✓ Restart counter: Working (incremented)"
else
print_warning "⚠ Restart counter: May not have incremented"
fi
echo
print_test "5. Testing monitoring mode (real-time updates)"
print_test "Testing monitoring mode for 10 seconds..."
echo "You should see real-time updates with changing uptime values:"
# Run monitoring mode in background for 10 seconds
timeout 10s cargo run --bin pmdaemon -- monitor 2>/dev/null || true
print_success "✓ Monitoring mode: Completed"
echo
print_test "6. Testing process stop and status changes"
print_test "Stopping process to test status changes..."
cargo run --bin pmdaemon -- stop "$TEST_APP_NAME"
sleep 2
STATUS_OUTPUT_4=$(cargo run --bin pmdaemon -- list)
echo "Status after stop:"
echo "$STATUS_OUTPUT_4"
# Check if status changed to stopped
if echo "$STATUS_OUTPUT_4" | grep "$TEST_APP_NAME" | grep -E "(stopped|offline)" > /dev/null; then
print_success "✓ Status change: Working (stopped)"
else
print_error "✗ Status change: Process may still show as running"
fi
# Check if PID is cleared
if echo "$STATUS_OUTPUT_4" | grep "$TEST_APP_NAME" | grep -E "\s+-\s+" > /dev/null; then
print_success "✓ PID clearing: Working (shows '-' when stopped)"
else
print_warning "⚠ PID clearing: May still show PID when stopped"
fi
echo
print_test "7. Summary of CLI Status Display Test"
echo "======================================"
echo "All major status fields have been tested:"
echo " • ID: Process UUID (8-char prefix)"
echo " • Name: Process name"
echo " • Status: Process state (online/stopped/etc.)"
echo " • PID: System process ID"
echo " • Uptime: Time since process started"
echo " • Restarts: Number of restarts"
echo " • CPU %: CPU usage percentage"
echo " • Memory: Memory usage with units"
echo " • Port: Assigned port number"
echo
print_success "CLI Status Display Test Complete!"
echo "Check the output above for any warnings or failures."
# Cleanup
rm -f test_config.json
echo
echo "To manually verify uptime is working:"
echo "1. Start a process: cargo run --bin pmdaemon -- start <config>"
echo "2. Run: cargo run --bin pmdaemon -- list"
echo "3. Wait a few seconds and run list again"
echo "4. Verify the uptime value increases"