-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-execution-time.sh
More file actions
executable file
·84 lines (67 loc) · 2.22 KB
/
test-execution-time.sh
File metadata and controls
executable file
·84 lines (67 loc) · 2.22 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
#!/bin/bash
# test-execution-time.sh
#
# Validate Test Execution Time
# Replica: Test Pyramid Validation / Validate Test Execution Time
#
# Exit codes:
# 0 - Test execution time is acceptable
# 1 - Tests are too slow or failed
# 2 - Prerequisites missing (skip)
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
log_info "Validating test execution time..."
cd "$PROJECT_ROOT/api/callcentersite"
# Activar entorno virtual
if [ -f "$PROJECT_ROOT/venv/bin/activate" ]; then
# shellcheck source=/dev/null
source "$PROJECT_ROOT/venv/bin/activate"
elif [ -f "$PROJECT_ROOT/.venv/bin/activate" ]; then
# shellcheck source=/dev/null
source "$PROJECT_ROOT/.venv/bin/activate"
fi
# Verificar dependencias mínimas
if ! python3 -c "import django" >/dev/null 2>&1; then
log_warn "Skipping test execution time validation: Django not installed"
exit 2
fi
if ! command -v pytest >/dev/null 2>&1; then
log_warn "Skipping test execution time validation: pytest CLI not available"
exit 2
fi
# Run tests with timing
log_info "Running tests with timing analysis..."
START_TIME=$(date +%s)
if pytest -v --durations=10 2>&1 | tee /tmp/test_timing.log; then
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
log_info "Total test duration: ${DURATION}s"
# Extract slowest tests
echo ""
log_info "Slowest tests:"
grep "slowest" /tmp/test_timing.log -A 10 || true
# Check for slow tests (> 5s)
SLOW_TESTS=$(grep -c "s call" /tmp/test_timing.log | grep -E "[5-9]\.[0-9]+s|[0-9]{2,}\.[0-9]+s" || echo "0")
if [ "$SLOW_TESTS" -gt 0 ]; then
log_warn "Found $SLOW_TESTS slow tests (>5s)"
fi
# Overall time threshold: 2 minutes for all tests
if [ $DURATION -gt 120 ]; then
log_error "Test suite is too slow (${DURATION}s > 120s)"
exit 1
else
log_info "Test execution time is acceptable"
exit 0
fi
else
log_error "Tests failed"
exit 1
fi