CircleCI
Bu kılavuz, otomatik performans testi için LoadFocus JMeter API Client'ı CircleCI ile nasıl entegre edeceğinizi açıklar.
Kurulum Adımları
1. Ortam Değişkenlerini Ekleyin
LoadFocus API kimlik bilgilerinizi CircleCI'da ortam değişkenleri olarak saklayın:
- CircleCI'da projenize gidin
- Project Settings > Environment Variables bölümüne gidin
- Aşağıdaki değişkenleri ekleyin:
LOADFOCUS_API_KEY: LoadFocus API anahtarınızLOADFOCUS_TEAM_ID: LoadFocus takım kimliğiniz
2. CircleCI İş Akışını Yapılandırın
Performans testini dahil etmek için .circleci/config.yml dosyanızı oluşturun veya güncelleyin:
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. Performans Sorunlarında Derlemeyi Başarısız Yapma
Performans eşikleri karşılanmadığında pipeline'ınızın başarısız olmasını sağlamak için "Run Performance Tests" adımını değiştirin:
- 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
Gelişmiş Yapılandırma
Paralel Test
Birden fazla performans testini paralel olarak çalıştırmak için:
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
CircleCI Entegrasyonu İçin İpuçları
Kaynak Tahsisi: CircleCI planınızın performans testlerini çalıştırmak için yeterli kaynaklara sahip olduğundan emin olun, özellikle uzun süreli testler için.
Zaman Aşımı Ayarları: Daha uzun testler için CircleCI'da iş zaman aşımını ayarlayın:
- run:name: Run Performance Testscommand: loadfocus-api jmeter run-test --name "Test_Name" --waitTimeout 3600no_output_timeout: 60mKoşullu Test: Performans testlerini yalnızca belirli dallarda veya belirli commit'ler için çalıştırın.
Bildirimler: Performans testi başarısızlıkları için bildirimler ayarlayın.
Daha fazla bilgi için CircleCI dokümantasyonuna ve LoadFocus API Client dokümantasyonuna başvurun.