CircleCI

Ez az útmutató bemutatja, hogyan integrálhatja a LoadFocus JMeter API klienst a CircleCI-vel az automatizált teljesítményteszteléshez.

Beállítási lépések

1. Környezeti változók hozzáadása

Tárolja LoadFocus API hitelesítő adatait környezeti változókként a CircleCI-ben:

  1. Navigáljon a projektjéhez a CircleCI-ben
  2. Lépjen a Project Settings > Environment Variables menüpontba
  3. Adja hozzá a következő változókat:
    • LOADFOCUS_API_KEY: Az Ön LoadFocus API kulcsa
    • LOADFOCUS_TEAM_ID: Az Ön LoadFocus csapat azonosítója

2. CircleCI munkafolyamat konfigurálása

Hozza létre vagy frissítse a .circleci/config.yml fájlt a teljesítménytesztelés hozzáadásával:

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. Build megbuktatása teljesítményproblémák esetén

A pipeline megbuktatásához, ha a teljesítmény küszöbértékek nem teljesülnek, módosítsa a "Run Performance Tests" lépést:

- 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

Haladó konfiguráció

Párhuzamos tesztelés

Több teljesítményteszt párhuzamos futtatásához:

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

Tippek a CircleCI integrációhoz

  1. Erőforrás-kiosztás: Győződjön meg róla, hogy CircleCI csomagja elegendő erőforrással rendelkezik a teljesítménytesztek futtatásához, különösen ha azok hosszan futnak.

  2. Időtúllépés beállítások: Hosszabb tesztek esetén állítsa be a feladat időtúllépését a CircleCI-ben:

    - run:
    name: Run Performance Tests
    command: loadfocus-api jmeter run-test --name "Test_Name" --waitTimeout 3600
    no_output_timeout: 60m
  3. Feltételes tesztelés: Csak bizonyos ágakon vagy meghatározott commitoknál futtasson teljesítményteszteket:

    performance_test:
    # Only run if commit message contains [PERF-TEST]
    when:
    condition:
    or:
    - equal: [ main, << pipeline.git.branch >> ]
    - matches:
    pattern: ".*\\[PERF-TEST\\].*"
    value: << pipeline.git.commit.message >>
  4. Értesítések: Állítson be értesítéseket teljesítményteszt hibák esetén:

    - run:
    name: Notify on Performance Test Failure
    command: |
    if [ $? -ne 0 ]; then
    curl -X POST -H "Content-Type: application/json" \
    -d '{"text":"Performance test failed for $CIRCLE_PROJECT_REPONAME"}' \
    $SLACK_WEBHOOK_URL
    fi
    when: on_fail

További információkért tekintse meg a CircleCI dokumentációt és a LoadFocus API kliens dokumentációt.