CircleCI
Deze handleiding legt uit hoe u de LoadFocus JMeter API Client integreert met CircleCI voor geautomatiseerde prestatietests.
Installatiestappen
1. Omgevingsvariabelen Toevoegen
Sla uw LoadFocus API-referenties op als omgevingsvariabelen in CircleCI:
- Navigeer naar uw project in CircleCI
- Ga naar Project Settings > Environment Variables
- Voeg de volgende variabelen toe:
LOADFOCUS_API_KEY: Uw LoadFocus API-sleutelLOADFOCUS_TEAM_ID: Uw LoadFocus team-ID
2. CircleCI Workflow Configureren
Maak of werk uw .circleci/config.yml-bestand bij om prestatietests op te nemen:
version: 2.1jobs:performance_test:docker:- image: cimg/node:16.13steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set apikey $LOADFOCUS_API_KEYloadfocus-api config set teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |loadfocus-api jmeter run-test \--name "CircleCI_${CIRCLE_PROJECT_REPONAME}_${CIRCLE_BRANCH}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json- store_artifacts:path: performance_results.jsondestination: performance-test-resultsworkflows:version: 2build_test_deploy:jobs:- build_and_test- performance_test:requires:- build_and_test- deploy:requires:- performance_testfilters:branches:only: main
3. De Build Laten Falen bij Prestatieproblemen
Om uw pipeline te laten falen wanneer prestatiedrempels niet worden gehaald, pas de stap "Run Performance Tests" aan:
- run:name: Run Performance Testscommand: |loadfocus-api jmeter run-test \--name "CircleCI_${CIRCLE_PROJECT_REPONAME}_${CIRCLE_BRANCH}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json# Check exit code - the command will exit with code 1 if thresholds are not metif [ $? -ne 0 ]; thenecho "Performance test failed to meet thresholds"exit 1fi
Geavanceerde Configuratie
Parallel Testen
Voor het parallel uitvoeren van meerdere prestatietests:
performance_tests:docker:- image: cimg/node:16.13parallelism: 3steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set apikey $LOADFOCUS_API_KEYloadfocus-api config set teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |# Get test name based on indexTESTS=("API_Test" "Frontend_Test" "Database_Test")INDEX=$(( $CIRCLE_NODE_INDEX % 3 ))TEST_NAME=${TESTS[$INDEX]}echo "Running test: $TEST_NAME"loadfocus-api jmeter run-test \--name "$TEST_NAME" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > "performance_results_${TEST_NAME}.json"- store_artifacts:path: performance_results_*.jsondestination: performance-test-results
Tips voor CircleCI Integratie
Resource Toewijzing: Zorg ervoor dat uw CircleCI-plan voldoende resources heeft voor het uitvoeren van prestatietests, vooral als ze langlopend zijn.
Timeout Instellingen: Pas voor langere tests de job-timeout aan in CircleCI.
Voorwaardelijk Testen: Voer prestatietests alleen uit op specifieke branches of voor specifieke commits.
Meldingen: Stel meldingen in voor mislukte prestatietests.
Voor meer informatie, raadpleeg de CircleCI documentatie en de LoadFocus API Client documentatie.