CircleCI

이 가이드에서는 자동화된 성능 테스트를 위해 LoadFocus JMeter API Client를 CircleCI와 통합하는 방법을 설명합니다.

설정 단계

1. 환경 변수 추가

LoadFocus API 자격 증명을 CircleCI에 환경 변수로 저장합니다:

  1. CircleCI에서 프로젝트로 이동합니다
  2. Project Settings > Environment Variables로 이동합니다
  3. 다음 변수를 추가합니다:
    • LOADFOCUS_API_KEY: LoadFocus API 키
    • LOADFOCUS_TEAM_ID: LoadFocus 팀 ID

2. CircleCI 워크플로 구성

성능 테스트를 포함하도록 .circleci/config.yml 파일을 생성하거나 업데이트합니다:

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. 성능 문제 시 빌드 실패 처리

성능 임계값을 충족하지 못할 때 파이프라인을 실패시키려면 "Run Performance Tests" 단계를 수정합니다:

- 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

고급 구성

병렬 테스트

여러 성능 테스트를 병렬로 실행하려면:

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

CircleCI 통합 팁

  1. Resource Allocation: Ensure your CircleCI plan has sufficient resources for running performance tests, especially if they're long-running.

  2. Timeout Settings: For longer tests, adjust the job timeout in CircleCI:

    - run:
    name: Run Performance Tests
    command: loadfocus-api jmeter run-test --name "Test_Name" --waitTimeout 3600
    no_output_timeout: 60m
  3. Conditional Testing: Only run performance tests on specific branches or for specific commits:

    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. Notifications: Set up notifications for performance test failures:

    - 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

자세한 내용은 CircleCI 문서LoadFocus API Client 문서를 참조하세요.