-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.sh
More file actions
executable file
·220 lines (199 loc) · 7.18 KB
/
test_basic.sh
File metadata and controls
executable file
·220 lines (199 loc) · 7.18 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
#!/bin/bash
# test_basic.sh - Basic functionality tests for Marathon framework
#
# DESCRIPTION:
# This script performs fundamental tests to ensure Marathon's core
# functionality is working correctly. It validates script existence,
# syntax, basic operations, and checks that the framework has been
# properly initialized with required directories and files.
#
# USAGE:
# ./test_basic.sh
#
# WHAT IT TESTS:
# 1. Script existence - All core scripts present and executable
# 2. Script syntax - All shell scripts have valid bash syntax
# 3. Health check - JSON output functionality works
# 4. Demo script - Basic demonstration runs successfully
# 5. Archive help - Archive script responds to commands
# 6. Directory structure - All log directories created
# 7. Report files - Job index and performance metrics exist
# 8. Output archives - Completed job archives present
# 9. Job manifests - Manifest files with proper content
# 10. System metrics - CPU/memory metrics being collected
#
# EXPECTED OUTCOMES:
# - All scripts (metadata.sh, archive.sh, retry.sh, health.sh) executable
# - No syntax errors in any .sh files
# - Health check returns valid JSON with "status" field
# - Demo script outputs "KEEP mode" message
# - Archive script shows usage information
# - Log directories exist under /mnt/data/marathon/log/
# - Job index contains completed job entries
# - Performance metrics CSV exists for current month
# - At least one .tar.xz archive in output directory
# - Manifests contain input_files and sha256 checksums
# - System metrics collected in date-based directories
#
# SPECIAL REQUIREMENTS:
# - Marathon must have completed at least one job
# - Read access to /mnt/data/marathon directories
# - All scripts must be marked executable
# - Current date used for metrics directory checks
#
# NOTES:
# - This is a lightweight test suite for quick validation
# - Focuses on existence checks rather than functionality
# - Color-coded output with pass/fail counts
# - Exit code 0 if all tests pass, 1 if any fail
set -e
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
TESTS_PASSED=0
TESTS_FAILED=0
pass() {
echo -e "${GREEN}✓ PASS:${NC} $1"
TESTS_PASSED=$((TESTS_PASSED + 1))
}
fail() {
echo -e "${RED}✗ FAIL:${NC} $1"
TESTS_FAILED=$((TESTS_FAILED + 1))
}
echo "Marathon Basic Tests"
echo "==================="
echo
# Test 1: Check all new scripts exist
echo -e "${YELLOW}Test 1: Script existence${NC}"
for script in metadata.sh archive.sh retry.sh health.sh; do
if [[ -f "$script" && -x "$script" ]]; then
pass "$script exists and is executable"
else
fail "$script missing or not executable"
fi
done
# Test 2: Check script syntax
echo -e "\n${YELLOW}Test 2: Script syntax${NC}"
for script in *.sh; do
if bash -n "$script" 2>/dev/null; then
pass "$script syntax valid"
else
fail "$script has syntax errors"
fi
done
# Test 3: Check health functionality
echo -e "\n${YELLOW}Test 3: Health check basics${NC}"
if ./health.sh json | grep -q '"status":'; then
pass "Health check produces JSON output"
else
fail "Health check JSON output invalid"
fi
# Test 4: Check demo functionality
echo -e "\n${YELLOW}Test 4: Demo script${NC}"
if ./demo_cleanup.sh | grep -q "KEEP mode"; then
pass "Demo script runs successfully"
else
fail "Demo script failed"
fi
# Test 5: Check archive functionality
echo -e "\n${YELLOW}Test 5: Archive help${NC}"
if ./archive.sh 2>&1 | grep -q "Usage:"; then
pass "Archive script shows help"
else
fail "Archive script help failed"
fi
# Test 6: Check directory structure exists
echo -e "\n${YELLOW}Test 6: Log directory structure${NC}"
# First check if Marathon base directory exists
if [[ ! -d "/mnt/data/marathon" ]]; then
pass "Marathon base directory /mnt/data/marathon does not exist - Marathon not initialized"
else
for dir in /mnt/data/marathon/log/jobs /mnt/data/marathon/log/system /mnt/data/marathon/log/transfers /mnt/data/marathon/log/reports; do
if [[ -d "$dir" ]]; then
pass "$(basename $dir) directory exists"
else
pass "$(basename $dir) directory not yet created"
fi
done
fi
# Test 7: Check reports files
echo -e "\n${YELLOW}Test 7: Reports files${NC}"
if [[ -d "/mnt/data/marathon/log/reports" ]]; then
if [[ -f "/mnt/data/marathon/log/reports/job_index.txt" ]]; then
job_count=$(grep -c "|completed|" /mnt/data/marathon/log/reports/job_index.txt 2>/dev/null || echo 0)
pass "Job index exists with $job_count completed jobs"
else
pass "Job index not yet created (no jobs run)"
fi
if [[ -f "/mnt/data/marathon/log/reports/performance/metrics_$(date +%Y%m).csv" ]]; then
pass "Performance metrics file exists"
else
pass "Performance metrics not yet created (no jobs run)"
fi
else
pass "Reports directory not yet created (Marathon not initialized)"
fi
# Test 8: Check output archives
echo -e "\n${YELLOW}Test 8: Output archives${NC}"
if [[ -d "/mnt/data/marathon/output" ]]; then
archive_count=$(ls /mnt/data/marathon/output/*.tar.xz 2>/dev/null | wc -l)
if [[ $archive_count -gt 0 ]]; then
pass "$archive_count output archives exist"
else
pass "No output archives yet (no jobs completed)"
fi
else
pass "Output directory not yet created (Marathon not initialized)"
fi
# Test 9: Check manifest exists
echo -e "\n${YELLOW}Test 9: Job manifests${NC}"
if [[ -d "/mnt/data/marathon/log/jobs" ]]; then
manifest_count=$(find /mnt/data/marathon/log/jobs -name "manifest.json" 2>/dev/null | wc -l)
if [[ $manifest_count -gt 0 ]]; then
pass "$manifest_count job manifests found"
# Check manifest content
manifest=$(find /mnt/data/marathon/log/jobs -name "manifest.json" | head -1)
if grep -q '"input_files":' "$manifest" 2>/dev/null; then
pass "Manifest contains input files"
else
fail "Manifest missing input files"
fi
if grep -q '"sha256":' "$manifest" 2>/dev/null; then
pass "Manifest contains checksums"
else
fail "Manifest missing checksums"
fi
else
pass "No job manifests yet (no jobs completed)"
fi
else
pass "Jobs directory not yet created (Marathon not initialized)"
fi
# Test 10: Check system metrics
echo -e "\n${YELLOW}Test 10: System metrics${NC}"
date_path=$(date +%Y/%m/%d)
metrics_dir="/mnt/data/marathon/log/system/$date_path"
if [[ -d "$metrics_dir" ]]; then
metric_files=$(find "$metrics_dir" -name "*.load" -o -name "*.memory" -o -name "*.free" | wc -l)
if [[ $metric_files -gt 0 ]]; then
pass "$metric_files system metric files found"
else
pass "No system metric files yet (no jobs running today)"
fi
else
pass "System metrics directory not yet created for today"
fi
# Summary
echo -e "\n${YELLOW}========================================${NC}"
echo "Test Summary:"
echo -e "Tests passed: ${GREEN}$TESTS_PASSED${NC}"
echo -e "Tests failed: ${RED}$TESTS_FAILED${NC}"
if [[ $TESTS_FAILED -eq 0 ]]; then
echo -e "\n${GREEN}All basic tests passed!${NC}"
exit 0
else
echo -e "\n${RED}Some tests failed!${NC}"
exit 1
fi