|
| 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 }} |
0 commit comments