Skip to content

Commit 0d7a24c

Browse files
committed
feat: add automated performance testing for term info queries with GitHub Actions
1 parent 23a5ee0 commit 0d7a24c

5 files changed

Lines changed: 295 additions & 1 deletion

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Performance Test
2+
3+
on:
4+
push:
5+
branches: [ main, dev ]
6+
pull_request:
7+
branches: [ main, dev ]
8+
workflow_dispatch: # Enables manual triggering
9+
schedule:
10+
- cron: '0 2 * * *' # Runs daily at 2 AM UTC
11+
12+
jobs:
13+
performance:
14+
name: "Performance Test"
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 60 # Set a timeout to prevent jobs from running indefinitely
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.8'
25+
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install --upgrade -r requirements.txt
30+
python -m pip install .
31+
32+
- name: Run Performance Test
33+
run: |
34+
export PYTHONPATH=$PYTHONPATH:$PWD/
35+
echo "Running performance test for term info queries..."
36+
python -m unittest -v src.test.term_info_queries_test.TermInfoQueriesTest.test_term_info_performance 2>&1 | tee performance_test_output.log
37+
continue-on-error: true # Continue even if performance thresholds are exceeded
38+
39+
- name: Create Performance Report
40+
if: always() # Always run this step, even if the test fails
41+
run: |
42+
# Create performance.md file
43+
cat > performance.md << 'EOF'
44+
# VFBquery Performance Test Results
45+
46+
**Test Date:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')
47+
**Git Commit:** ${{ github.sha }}
48+
**Branch:** ${{ github.ref_name }}
49+
**Workflow Run:** ${{ github.run_id }}
50+
51+
## Test Overview
52+
53+
This performance test measures the execution time of VFB term info queries for specific terms:
54+
55+
- **FBbt_00003748**: mushroom body (anatomical class)
56+
- **VFB_00101567**: individual anatomy data
57+
58+
## Performance Thresholds
59+
60+
- Maximum single query time: 30 seconds
61+
- Maximum total time for both queries: 45 seconds
62+
63+
## Test Results
64+
65+
```
66+
$(cat performance_test_output.log)
67+
```
68+
69+
## Summary
70+
71+
EOF
72+
73+
# Extract timing information from the test output
74+
if grep -q "Performance Test Results:" performance_test_output.log; then
75+
echo "✅ **Test Status**: Performance test completed" >> performance.md
76+
echo "" >> performance.md
77+
78+
# Extract timing data
79+
if grep -q "FBbt_00003748 query took:" performance_test_output.log; then
80+
TIMING1=$(grep "FBbt_00003748 query took:" performance_test_output.log | sed 's/.*took: \([0-9.]*\) seconds.*/\1/')
81+
echo "- **FBbt_00003748 Query Time**: ${TIMING1} seconds" >> performance.md
82+
fi
83+
84+
if grep -q "VFB_00101567 query took:" performance_test_output.log; then
85+
TIMING2=$(grep "VFB_00101567 query took:" performance_test_output.log | sed 's/.*took: \([0-9.]*\) seconds.*/\1/')
86+
echo "- **VFB_00101567 Query Time**: ${TIMING2} seconds" >> performance.md
87+
fi
88+
89+
if grep -q "Total time for both queries:" performance_test_output.log; then
90+
TOTAL_TIME=$(grep "Total time for both queries:" performance_test_output.log | sed 's/.*queries: \([0-9.]*\) seconds.*/\1/')
91+
echo "- **Total Query Time**: ${TOTAL_TIME} seconds" >> performance.md
92+
fi
93+
94+
# Check if test passed or failed
95+
if grep -q "OK" performance_test_output.log; then
96+
echo "" >> performance.md
97+
echo "🎉 **Result**: All performance thresholds met!" >> performance.md
98+
elif grep -q "FAILED" performance_test_output.log; then
99+
echo "" >> performance.md
100+
echo "⚠️ **Result**: Some performance thresholds exceeded or test failed" >> performance.md
101+
fi
102+
else
103+
echo "❌ **Test Status**: Performance test failed to run properly" >> performance.md
104+
fi
105+
106+
echo "" >> performance.md
107+
echo "---" >> performance.md
108+
echo "*Last updated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')*" >> performance.md
109+
110+
# Also add to GitHub step summary
111+
echo "## Performance Test Report" >> $GITHUB_STEP_SUMMARY
112+
echo "Performance results have been saved to performance.md" >> $GITHUB_STEP_SUMMARY
113+
echo "" >> $GITHUB_STEP_SUMMARY
114+
cat performance.md >> $GITHUB_STEP_SUMMARY
115+
116+
- name: Commit Performance Report
117+
if: always()
118+
run: |
119+
git config --local user.email "action@github.com"
120+
git config --local user.name "GitHub Action"
121+
git add performance.md
122+
git diff --staged --quiet || git commit -m "Update performance test results [skip ci]"
123+
124+
- name: Push Performance Report
125+
if: always()
126+
uses: ad-m/github-push-action@master
127+
with:
128+
github_token: ${{ secrets.GITHUB_TOKEN }}
129+
branch: ${{ github.ref }}

README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,37 @@ vfb.get_term_info('VFB_00101567')
10261026
}
10271027
```
10281028

1029-
Queries:
1029+
## Performance Testing
1030+
1031+
VFBquery includes automated performance testing to monitor query response times. The performance test measures execution time for specific queries:
1032+
1033+
- **FBbt_00003748** (mushroom body - anatomical class)
1034+
- **VFB_00101567** (individual anatomy data)
1035+
1036+
### Performance Thresholds
1037+
1038+
- Maximum single query time: 30 seconds
1039+
- Maximum total time for both queries: 45 seconds
1040+
1041+
### Automated Testing
1042+
1043+
Performance tests run automatically via GitHub Actions:
1044+
1045+
- **Daily**: Every day at 2 AM UTC
1046+
- **On commits**: Push to main/dev branches and pull requests
1047+
- **Manual**: Can be triggered manually from the Actions tab
1048+
1049+
Results are automatically saved to [`performance.md`](performance.md) in the repository root.
1050+
1051+
### Running Performance Tests Locally
1052+
1053+
```bash
1054+
# Install dependencies and run performance test
1055+
pip install -r requirements.txt
1056+
python -m unittest src.test.term_info_queries_test.TermInfoQueriesTest.test_term_info_performance -v
1057+
```
1058+
1059+
## Queries
10301060
```python
10311061
vfb.get_instances('FBbt_00003748', return_dataframe=False)
10321062
```

performance.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# VFBquery Performance Test Results
2+
3+
> **Note**: This file is automatically generated and updated by the GitHub Actions performance test workflow.
4+
5+
**Test Date:** *Not yet run*
6+
**Git Commit:** *N/A*
7+
**Branch:** *N/A*
8+
**Workflow Run:** *N/A*
9+
10+
## Test Overview
11+
12+
This performance test measures the execution time of VFB term info queries for specific terms:
13+
14+
- **FBbt_00003748**: mushroom body (anatomical class)
15+
- **VFB_00101567**: individual anatomy data
16+
17+
## Performance Thresholds
18+
19+
- Maximum single query time: 30 seconds
20+
- Maximum total time for both queries: 45 seconds
21+
22+
## Test Results
23+
24+
*No test results available yet. Run the performance test workflow to generate results.*
25+
26+
## Summary
27+
28+
**Test Status**: Waiting for first run
29+
30+
---
31+
*This file is automatically updated by the GitHub Actions performance test workflow.*

src/test/term_info_queries_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,51 @@ def test_term_info_serialization_pub(self):
524524
self.assertFalse("filemeta" in serialized)
525525
self.assertFalse("template" in serialized)
526526

527+
def test_term_info_performance(self):
528+
"""
529+
Performance test for specific term info queries.
530+
Tests the execution time for FBbt_00003748 and VFB_00101567.
531+
"""
532+
import vfbquery as vfb
533+
534+
# Test performance for FBbt_00003748 (mushroom body)
535+
start_time = time.time()
536+
result_1 = vfb.get_term_info('FBbt_00003748')
537+
duration_1 = time.time() - start_time
538+
539+
# Test performance for VFB_00101567 (individual anatomy)
540+
start_time = time.time()
541+
result_2 = vfb.get_term_info('VFB_00101567')
542+
duration_2 = time.time() - start_time
543+
544+
# Print performance metrics for GitHub Actions logs
545+
print(f"\n" + "="*50)
546+
print(f"Performance Test Results:")
547+
print(f"="*50)
548+
print(f"FBbt_00003748 query took: {duration_1:.4f} seconds")
549+
print(f"VFB_00101567 query took: {duration_2:.4f} seconds")
550+
print(f"Total time for both queries: {duration_1 + duration_2:.4f} seconds")
551+
print(f"="*50)
552+
553+
# Basic assertions to ensure the queries succeeded
554+
self.assertIsNotNone(result_1, "FBbt_00003748 query returned None")
555+
self.assertIsNotNone(result_2, "VFB_00101567 query returned None")
556+
557+
# Performance assertions - fail if queries take too long
558+
# These are reasonable thresholds that can be adjusted based on actual performance
559+
max_single_query_time = 30.0 # seconds
560+
max_total_time = 45.0 # seconds
561+
562+
self.assertLess(duration_1, max_single_query_time,
563+
f"FBbt_00003748 query took {duration_1:.4f}s, exceeding {max_single_query_time}s threshold")
564+
self.assertLess(duration_2, max_single_query_time,
565+
f"VFB_00101567 query took {duration_2:.4f}s, exceeding {max_single_query_time}s threshold")
566+
self.assertLess(duration_1 + duration_2, max_total_time,
567+
f"Total query time {duration_1 + duration_2:.4f}s exceeds {max_total_time}s threshold")
568+
569+
# Log success
570+
print("Performance test completed successfully!")
571+
527572

528573
class TestVariable:
529574

test_parsing.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Test script to simulate the GitHub Actions workflow parsing
4+
# This helps verify our parsing logic works correctly
5+
6+
echo "Testing performance report generation..."
7+
8+
# Create mock test output
9+
cat > test_output.log << 'EOF'
10+
test_term_info_performance (src.test.term_info_queries_test.TermInfoQueriesTest)
11+
Performance test for specific term info queries. ...
12+
==================================================
13+
Performance Test Results:
14+
==================================================
15+
FBbt_00003748 query took: 1.3683 seconds
16+
VFB_00101567 query took: 0.0500 seconds
17+
Total time for both queries: 1.4183 seconds
18+
==================================================
19+
Performance test completed successfully!
20+
ok
21+
22+
----------------------------------------------------------------------
23+
Ran 1 test in 1.418s
24+
25+
OK
26+
EOF
27+
28+
# Extract timing information (same logic as in the workflow)
29+
if grep -q "Performance Test Results:" test_output.log; then
30+
echo "✅ Found performance results"
31+
32+
if grep -q "FBbt_00003748 query took:" test_output.log; then
33+
TIMING1=$(grep "FBbt_00003748 query took:" test_output.log | sed 's/.*took: \([0-9.]*\) seconds.*/\1/')
34+
echo "- FBbt_00003748 Query Time: ${TIMING1} seconds"
35+
fi
36+
37+
if grep -q "VFB_00101567 query took:" test_output.log; then
38+
TIMING2=$(grep "VFB_00101567 query took:" test_output.log | sed 's/.*took: \([0-9.]*\) seconds.*/\1/')
39+
echo "- VFB_00101567 Query Time: ${TIMING2} seconds"
40+
fi
41+
42+
if grep -q "Total time for both queries:" test_output.log; then
43+
TOTAL_TIME=$(grep "Total time for both queries:" test_output.log | sed 's/.*queries: \([0-9.]*\) seconds.*/\1/')
44+
echo "- Total Query Time: ${TOTAL_TIME} seconds"
45+
fi
46+
47+
if grep -q "OK" test_output.log; then
48+
echo "🎉 Result: All performance thresholds met!"
49+
elif grep -q "FAILED" test_output.log; then
50+
echo "⚠️ Result: Some performance thresholds exceeded or test failed"
51+
fi
52+
else
53+
echo "❌ No performance results found"
54+
fi
55+
56+
# Clean up
57+
rm test_output.log
58+
59+
echo "Parsing test completed!"

0 commit comments

Comments
 (0)