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:

  1. Navigeer naar uw project in CircleCI
  2. Ga naar Project Settings > Environment Variables
  3. Voeg de volgende variabelen toe:
    • LOADFOCUS_API_KEY: Uw LoadFocus API-sleutel
    • LOADFOCUS_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.1
jobs:
performance_test:
docker:
- image: cimg/node:16.13
steps:
- checkout
- run:
name: Install LoadFocus JMeter API Client
command: npm install -g @loadfocus/loadfocus-api-client
- run:
name: Configure LoadFocus API Client
command: |
loadfocus-api config set apikey $LOADFOCUS_API_KEY
loadfocus-api config set teamid $LOADFOCUS_TEAM_ID
- run:
name: Run Performance Tests
command: |
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.json
destination: performance-test-results
workflows:
version: 2
build_test_deploy:
jobs:
- build_and_test
- performance_test:
requires:
- build_and_test
- deploy:
requires:
- performance_test
filters:
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 Tests
command: |
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 met
if [ $? -ne 0 ]; then
echo "Performance test failed to meet thresholds"
exit 1
fi

Geavanceerde Configuratie

Parallel Testen

Voor het parallel uitvoeren van meerdere prestatietests:

performance_tests:
docker:
- image: cimg/node:16.13
parallelism: 3
steps:
- checkout
- run:
name: Install LoadFocus JMeter API Client
command: npm install -g @loadfocus/loadfocus-api-client
- run:
name: Configure LoadFocus API Client
command: |
loadfocus-api config set apikey $LOADFOCUS_API_KEY
loadfocus-api config set teamid $LOADFOCUS_TEAM_ID
- run:
name: Run Performance Tests
command: |
# Get test name based on index
TESTS=("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_*.json
destination: performance-test-results

Tips voor CircleCI Integratie

  1. Resource Toewijzing: Zorg ervoor dat uw CircleCI-plan voldoende resources heeft voor het uitvoeren van prestatietests, vooral als ze langlopend zijn.

  2. Timeout Instellingen: Pas voor langere tests de job-timeout aan in CircleCI.

  3. Voorwaardelijk Testen: Voer prestatietests alleen uit op specifieke branches of voor specifieke commits.

  4. Meldingen: Stel meldingen in voor mislukte prestatietests.

Voor meer informatie, raadpleeg de CircleCI documentatie en de LoadFocus API Client documentatie.