Automatiser
Tests de charge dans un pipeline de CI
Conditionner un pipeline GitHub, GitLab ou de toute autre CI au verdict d’un test de charge, avec un fichier prêt de votre serveur.
Un pipeline de CI (GitHub Actions, GitLab CI/CD, Jenkins...) peut lancer un test de charge à chaque livraison et arrêter la livraison quand le test ne passe pas. Le job lance le test, attend son verdict et échoue sauf si le test a réussi. Vous n’écrivez pas ce job vous-même : votre serveur Swarmetry fournit quatre fichiers prêts, avec sa propre adresse déjà écrite dedans.
| Fichier | Pour | Où le mettre |
|---|---|---|
github-workflow.yml |
GitHub Actions : un workflow complet | .github/workflows/swarmetry.yml dans votre dépôt |
github-action.yml |
GitHub Actions : une étape à ajouter à vos propres workflows | .github/actions/swarmetry/action.yml dans votre dépôt |
gitlab-ci.yml |
GitLab CI/CD : un job | votre .gitlab-ci.yml |
swarmetry-ci.sh |
Toute autre CI (Jenkins, Azure Pipelines, Bitbucket Pipelines...) : un script shell | votre dépôt, lancé par sh swarmetry-ci.sh |
Les mêmes fichiers sont listés dans Aide > Accès développeur (/app/developer), sous L’utiliser dans un pipeline
de CI. Ils utilisent la ligne de commande swarmetry (page 28), qu’ils téléchargent depuis votre
serveur. Les fichiers sont en anglais, comme les commentaires qu’ils contiennent.
Avant de commencer
- Un test qui décide. Le verdict vient des seuils de la configuration de test (Seuils), par exemple « 95 % des requêtes répondent en moins de 500 ms ». Sans seuil, un test n’a pas de verdict, et le job échoue avec le code 22.
- Une cible vérifiée. Le test n’envoie de charge que vers les domaines que votre organisation a vérifiés (page 4).
- Un jeton pour le pipeline. Créez un compte de service avec les permissions de lancer des tests et de lire
leurs résultats, et un jeton de ce compte (page 31). Gardez le jeton (il commence par
sw_sat_) dans le coffre de secrets de votre CI, sous le nomSWARMETRY_TOKEN. Un jeton personnel fonctionne aussi, mais cesse de fonctionner quand vous quittez l’organisation. - Les identifiants du test. Ouvrez la configuration de test dans Swarmetry : son adresse contient les trois
identifiants dont les modèles ont besoin,
/app/projects/<projet>/scenarios/<scénario>/configs/<configuration de test>. Avec la ligne de commande :swarmetry project list,swarmetry scenario list --project-id <id>, puisswarmetry test-config list --project-id <id> --scenario-id <id>. - Plages d’adresses IP autorisées. Si votre organisation n’accepte que certaines adresses (Administration > Politiques de sécurité), ajoutez les adresses de vos exécuteurs de CI. Les exécuteurs hébergés par GitHub ou GitLab utilisent de nombreuses adresses qui changent : un exécuteur à vous, avec une adresse fixe, est plus simple.
Ce que fait chaque modèle
- Il installe la ligne de commande depuis votre serveur, jamais depuis ailleurs, en https seulement (TLS 1.2 ou
plus récent, jamais de redirection vers http), et la vérifie : avec le SHA-256 que vous avez épinglé dans votre dépôt
(Épingler la ligne de commande, le choix sûr), sinon avec le fichier
SHA256SUMSde votre serveur, lui-même vérifié avec la clé de publication de Swarmetry une fois celle-ci publiée (Sommes de contrôle et signature). Si une vérification échoue, rien n’est lancé. - Il lance le test avec
-y --wait. Un test envoie de la charge vers votre site et utilise les quotas de votre offre : la ligne de commande demande donc une confirmation. Un pipeline n’a pas de terminal pour répondre, et sans-yle lancement est refusé (code 10). En écrivant-ydans votre pipeline, vous confirmez chaque test qu’il lance. - Il lance la pré-vérification que votre organisation exige, si elle en exige une (
--preflight-if-required) : quand la politique de lancement demande une pré-vérification réussie avant un test de cette taille, la ligne de commande la lance d’abord (un court test réel avec quelques utilisateurs virtuels), attend son résultat et lance le test avec elle. Une pré-vérification qui ne réussit pas termine le job avec le code 26 et ce qu’elle a trouvé : le test n’est pas lancé. - Il attend le verdict, au plus
SWARMETRY_TIMEOUT(1 heure par défaut), puis arrête le test (code 25). - Il écrit le JUnit XML du test,
swarmetry-junit.xml, même quand le test échoue : le verdict, chaque seuil et chaque vérification sont des cas de test. Sur GitHub, le résumé du job montre aussi le verdict et les seuils en échec. - Il se termine avec le code du verdict et une ligne qui dit ce qu’il signifie (tableau plus bas).
- Il note d’où vient le test : le test affiche « GitHub Actions acme/shop main 0123abc » (ou l’équivalent GitLab) dans Swarmetry.
- Il arrête le test quand le job est annulé : la ligne de commande arrête le test qu’elle a lancé, puis se termine avec le code 130.
- Il n’affiche jamais le jeton : la ligne de commande le lit dans l’environnement (
SWARMETRY_TOKEN) ; il n’est jamais sur une ligne de commande ni dans un fichier de votre dépôt.
Les modèles ne lancent le test que quand vous le demandez (le bouton Run workflow de GitHub, New pipeline de GitLab). Chaque fichier indique, dans un commentaire, comment le lancer plutôt à chaque push sur votre branche principale : chaque test utilise alors les quotas de votre offre.
Épingler la ligne de commande
Par défaut, un modèle lance à chaque exécution le fichier que votre serveur sert, vérifié avec les sommes de contrôle de ce même serveur. Épingler est le choix sûr : vous enregistrez dans votre dépôt la version et le SHA-256 du fichier de votre exécuteur, et le job ne lance que ce fichier. Personne qui pourrait modifier ce que sert votre serveur ne peut alors lancer un autre programme dans votre pipeline. Après une mise à jour de votre serveur, le job s’arrête, dit que le serveur sert une autre ligne de commande et affiche le SHA-256 du nouveau fichier : vérifiez-le, puis épinglez la nouvelle version dans un commit relu comme les autres.
-
Ouvrez Aide > Accès développeur et notez la version et le SHA-256 du fichier de votre exécuteur :
swarmetry-linux-amd64pour les exécuteurs Linux de GitHub et de GitLab,swarmetry-linux-arm64sur les exécuteurs ARM,swarmetry-darwin-arm64sur les exécuteurs Apple silicon. Sa ligne deSHA256SUMSdonne le même SHA-256. -
Écrivez les deux valeurs dans le fichier de votre pipeline, dans votre dépôt :
Modèle Version SHA-256 github-workflow.ymlSWARMETRY_CLI_VERSIONsousenvSWARMETRY_CLI_SHA256sousenvgithub-action.ymlentrée cli-versionentrée cli-sha256gitlab-ci.ymlSWARMETRY_CLI_VERSIONsousvariablesSWARMETRY_CLI_SHA256sousvariablesswarmetry-ci.shSWARMETRY_CLI_VERSIONSWARMETRY_CLI_SHA256(dans la définition du job gardée dans votre dépôt, par exemple l’environmentd’un Jenkinsfile)Par exemple, dans le workflow :
SWARMETRY_CLI_VERSION: 'v4.0.0' SWARMETRY_CLI_SHA256: '<les 64 caractères de la page>' -
Faites un commit. Gardez les valeurs dans le dépôt, pas dans les réglages de votre CI : elles y sont relues comme du code. Sur GitLab, une variable de projet ou une variable donnée au lancement d’un pipeline remplace la valeur du job : n’en définissez aucune pour ces noms.
Avec les deux valeurs, le job ne lit pas du tout SHA256SUMS : c’est le SHA-256 de votre dépôt qui fait foi. Une
valeur sans l’autre est refusée (set both) ; un fichier d’une autre version aussi.
GitHub Actions
Un workflow
- Dans votre dépôt, ouvrez Settings > Secrets and variables > Actions.
- Sous Secrets, ajoutez
SWARMETRY_TOKEN: le jeton du compte de service. - Sous Variables, ajoutez
SWARMETRY_PROJECT_ID,SWARMETRY_SCENARIO_IDetSWARMETRY_TEST_CONFIG_ID. Facultatif :SWARMETRY_TIMEOUT(par exemple30m),SWARMETRY_ENVIRONMENT_ID,SWARMETRY_ALLOW_INCONCLUSIVE. - Enregistrez le fichier ci-dessous sous
.github/workflows/swarmetry.yml, poussez-le, puis ouvrez l’onglet Actions et choisissez Load test > Run workflow.
# Swarmetry load test gate for GitHub Actions: a workflow.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/github-workflow.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Save it as .github/workflows/swarmetry.yml in your repository. Then, in Settings > Secrets and variables > Actions:
# - secret SWARMETRY_TOKEN: the token of a service account (sw_sat_...), Administration > Service accounts;
# - variables SWARMETRY_PROJECT_ID, SWARMETRY_SCENARIO_ID, SWARMETRY_TEST_CONFIG_ID: the address of the test
# configuration in Swarmetry holds the three ids (/app/projects/<project>/scenarios/<scenario>/configs/<config>).
# The job installs the command line from your server, starts the test with -y (a pipeline has no terminal: -y confirms
# a test that sends load and uses the quotas of your plan), waits for its verdict, writes the job summary and keeps the
# JUnit XML. It fails when the test does not pass. Optional variables: SWARMETRY_ALLOW_INCONCLUSIVE=1 lets an
# inconclusive test pass with a warning, SWARMETRY_TIMEOUT (default 1h).
# The command line is checked against the SHA-256 pinned below (SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256, the
# secure choice: the version and the SHA-256 of swarmetry-linux-amd64 on the page Developer access), otherwise against
# SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below. Downloads are
# https only, TLS 1.2 or later, never redirected to http.
name: Load test
on:
workflow_dispatch: # the "Run workflow" button of the Actions tab
# push:
# branches: [main] # every push to main: each test uses the quotas of your plan
permissions:
contents: read
jobs:
load-test:
runs-on: ubuntu-latest
timeout-minutes: 90
defaults:
run:
shell: bash
env:
SWARMETRY_URL: 'https://swarmetry.io'
# Pinned command line: for example SWARMETRY_CLI_VERSION 'v4.0.0' and SWARMETRY_CLI_SHA256 '<64 hexadecimal
# characters>'. Empty: the file your server serves.
SWARMETRY_CLI_VERSION: ''
SWARMETRY_CLI_SHA256: ''
SWARMETRY_PROJECT_ID: ${{ vars.SWARMETRY_PROJECT_ID }}
SWARMETRY_SCENARIO_ID: ${{ vars.SWARMETRY_SCENARIO_ID }}
SWARMETRY_TEST_CONFIG_ID: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
SWARMETRY_ENVIRONMENT_ID: ${{ vars.SWARMETRY_ENVIRONMENT_ID }}
SWARMETRY_TIMEOUT: ${{ vars.SWARMETRY_TIMEOUT || '1h' }}
steps:
- name: Install the Swarmetry command line from your server
env:
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
run: |
bin="$RUNNER_TEMP/swarmetry"
mkdir -p "$bin"
case "$(uname -m)" in
x86_64) name=swarmetry-linux-amd64 ;;
aarch64) name=swarmetry-linux-arm64 ;;
*) echo "::error::No command line for the processor $(uname -m)"; exit 1 ;;
esac
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "::error::SWARMETRY_URL must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
get "$SWARMETRY_URL/cli/files/$name" "$bin/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "::error::Pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"; exit 1
fi
got=$(sha256sum "$bin/$name" | cut -d ' ' -f 1)
if [ "$got" != "${SWARMETRY_CLI_SHA256,,}" ]; then
echo "::error title=Command line changed::Your server serves another command line than the one pinned in this workflow (its SHA-256: $got). If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
exit 1
fi
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" "$bin/SHA256SUMS"
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig"
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > "$bin/allowed_signers"
if ! ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' -s "$bin/SHA256SUMS.sig" < "$bin/SHA256SUMS"; then
echo "::error title=Signature::The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
exit 1
fi
fi
(cd "$bin" && awk -v n="$name" '$2 == n' SHA256SUMS | sha256sum -c -)
fi
chmod 0755 "$bin/$name"
mv "$bin/$name" "$bin/swarmetry"
version=$("$bin/swarmetry" --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "::error::The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"
exit 1
fi
echo "$bin" >> "$GITHUB_PATH"
echo "$version"
- name: Run the load test and wait for its verdict
env:
SWARMETRY_TOKEN: ${{ secrets.SWARMETRY_TOKEN }}
SWARMETRY_ALLOW_INCONCLUSIVE: ${{ vars.SWARMETRY_ALLOW_INCONCLUSIVE }}
run: |
if [ -z "$SWARMETRY_TOKEN" ]; then
echo "::error::The secret SWARMETRY_TOKEN is not set (the token of a service account)"
exit 1
fi
args=(run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID")
if [ -n "$SWARMETRY_TEST_CONFIG_ID" ]; then args+=(--test-config-id "$SWARMETRY_TEST_CONFIG_ID"); fi
if [ -n "$SWARMETRY_ENVIRONMENT_ID" ]; then args+=(--environment-id "$SWARMETRY_ENVIRONMENT_ID"); fi
args+=(--note "GitHub Actions $GITHUB_REPOSITORY $GITHUB_REF_NAME ${GITHUB_SHA:0:7}")
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
args+=(--preflight-if-required)
args+=(-y --wait --timeout "$SWARMETRY_TIMEOUT" --stop-on-timeout --junit swarmetry-junit.xml)
# A cancelled workflow signals this shell: pass it on, the command line stops the test it started.
swarmetry "${args[@]}" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do code=0; wait "$pid" || code=$?; done
case "$code" in
0) exit 0 ;;
20) echo "::error title=Load test failed::A threshold failed, or the test was stopped by a threshold" ;;
21)
if [ "$SWARMETRY_ALLOW_INCONCLUSIVE" = 1 ]; then
echo "::warning title=Load test inconclusive::Nothing failed, but the test cannot be declared passed"
exit 0
fi
echo "::error title=Load test inconclusive::Nothing failed, but the test cannot be declared passed (SWARMETRY_ALLOW_INCONCLUSIVE=1 lets it pass)"
;;
22) echo "::error title=No verdict::The test has no threshold: add thresholds to its test configuration" ;;
23) echo "::error title=Load test stopped::The test was stopped before its end" ;;
24) echo "::error title=Technical failure::The test failed for a technical reason (error code in the log): run the job again" ;;
25) echo "::error title=Timeout::The test was still running after $SWARMETRY_TIMEOUT and was stopped" ;;
26) echo "::error title=Preflight failed::The preflight the run policy requires did not pass (findings in the log), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "::error title=Token refused::The token was refused or has expired: update the secret SWARMETRY_TOKEN" ;;
4) echo "::error title=Refused::The start was refused (error code and hint in the log): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "::error title=Start refused::A rule of your organization refused the start (error code and hint in the log): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "::error title=Cannot start::The test cannot start as configured (error code and hint in the log): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "::error title=Quota reached::A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "::error title=Server unreachable::Check SWARMETRY_URL and the network of the runner" ;;
130) echo "::error title=Cancelled::The test this job started was stopped" ;;
*) echo "::error title=Load test::The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
- name: Keep the JUnit report
if: always()
uses: actions/upload-artifact@v7
with:
name: swarmetry-junit
path: swarmetry-junit.xml
if-no-files-found: ignore
Une étape pour vos propres workflows (action composite)
Utilisez-la quand le test de charge est une étape d’un workflow que vous avez déjà, par exemple après le déploiement
sur un serveur de préproduction. Swarmetry ne publie pas cette action sur GitHub : vous en gardez une copie dans votre
dépôt, que vos workflows peuvent toujours utiliser. Enregistrez le fichier ci-dessous sous
.github/actions/swarmetry/action.yml, puis ajoutez ces étapes à un job :
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/swarmetry
with:
token: ${{ secrets.SWARMETRY_TOKEN }}
project-id: ${{ vars.SWARMETRY_PROJECT_ID }}
scenario-id: ${{ vars.SWARMETRY_SCENARIO_ID }}
test-config-id: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
actions/checkout vient en premier parce que GitHub lit une action locale dans le dépôt récupéré. Entrées : token,
project-id, scenario-id (obligatoires), test-config-id, environment-id, timeout (1h), allow-inconclusive
('false'), junit-file (swarmetry-junit.xml), artifact-name (swarmetry-junit, '' ne garde aucun artefact),
url (votre serveur), cli-version et cli-sha256 (voir
Épingler la ligne de commande). Sortie : exit-code.
# Swarmetry load test gate for GitHub Actions: a composite action to keep in your repository.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/github-action.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Save it as .github/actions/swarmetry/action.yml in your repository, then use it in any job, after actions/checkout:
#
# permissions:
# contents: read
# steps:
# - uses: actions/checkout@v7
# - uses: ./.github/actions/swarmetry
# with:
# token: ${{ secrets.SWARMETRY_TOKEN }}
# project-id: ${{ vars.SWARMETRY_PROJECT_ID }}
# scenario-id: ${{ vars.SWARMETRY_SCENARIO_ID }}
# test-config-id: ${{ vars.SWARMETRY_TEST_CONFIG_ID }}
#
# token is the token of a service account (sw_sat_...), Administration > Service accounts, kept as a secret of your
# repository. The action installs the command line from your server, starts the test with -y (a pipeline has no
# terminal: -y confirms a test that sends load and uses the quotas of your plan), waits for its verdict, writes the job
# summary, keeps the JUnit XML as an artifact and fails the step when the test does not pass. Linux and macOS runners.
# The command line is checked against the SHA-256 pinned with the inputs cli-version and cli-sha256 (the secure choice:
# the version and the SHA-256 of the file of your runner on the page Developer access, written in your workflow),
# otherwise against SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below.
# Downloads are https only, TLS 1.2 or later, never redirected to http.
name: Swarmetry load test
description: Starts a Swarmetry load test, waits for its verdict and fails the step when the test does not pass.
inputs:
token:
description: Token of a Swarmetry service account (sw_sat_...). Pass a secret, never a value written in the workflow.
required: true
project-id:
description: Id of the project of the test.
required: true
scenario-id:
description: Id of the scenario to run.
required: true
test-config-id:
description: Id of the test configuration (load and thresholds). Recommended, the thresholds decide the verdict.
required: false
default: ''
environment-id:
description: Id of an environment of the project.
required: false
default: ''
timeout:
description: Longest wait for the verdict; then the test is stopped (for example 30m, 1h).
required: false
default: 1h
allow-inconclusive:
description: "'true' lets an inconclusive test pass with a warning."
required: false
default: 'false'
junit-file:
description: JUnit XML file written by the command line.
required: false
default: swarmetry-junit.xml
artifact-name:
description: Name of the artifact that keeps the JUnit file ('' keeps none).
required: false
default: swarmetry-junit
cli-version:
description: Pinned command line, with cli-sha256 (for example v4.0.0). Empty, the file your server serves.
required: false
default: ''
cli-sha256:
description: SHA-256 of the pinned file of your runner (swarmetry-linux-amd64 on GitHub's Linux runners).
required: false
default: ''
url:
description: Address of your Swarmetry server.
required: false
default: 'https://swarmetry.io'
outputs:
exit-code:
description: Exit code of the command line (0 pass, 20 fail, 21 inconclusive, 22 no threshold, 23 stopped, 24 technical failure, 25 timeout, 26 required preflight not passed).
value: ${{ steps.run.outputs.exit-code }}
runs:
using: composite
steps:
- name: Install the Swarmetry command line from your server
shell: bash
env:
SWARMETRY_URL: ${{ inputs.url }}
SWARMETRY_CLI_VERSION: ${{ inputs.cli-version }}
SWARMETRY_CLI_SHA256: ${{ inputs.cli-sha256 }}
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
run: |
bin="$RUNNER_TEMP/swarmetry"
mkdir -p "$bin"
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=darwin ;;
*) echo "::error::This action runs on Linux and macOS runners"; exit 1 ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) echo "::error::No command line for the processor $(uname -m)"; exit 1 ;;
esac
name="swarmetry-$os-$arch"
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "::error::The input url must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
if command -v sha256sum >/dev/null; then check=(sha256sum -c -); sum=(sha256sum); else check=(shasum -a 256 -c -); sum=(shasum -a 256); fi
get "$SWARMETRY_URL/cli/files/$name" "$bin/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "::error::Pinned command line: give both cli-version and cli-sha256"; exit 1
fi
got=$("${sum[@]}" "$bin/$name" | cut -d ' ' -f 1)
if [ "$got" != "$(printf '%s' "$SWARMETRY_CLI_SHA256" | tr 'A-F' 'a-f')" ]; then
echo "::error title=Command line changed::Your server serves another command line than the one pinned in your workflow (its SHA-256: $got). If your server was upgraded, check the new file on the page Developer access, then update cli-version and cli-sha256"
exit 1
fi
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" "$bin/SHA256SUMS"
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig"
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > "$bin/allowed_signers"
if ! ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' -s "$bin/SHA256SUMS.sig" < "$bin/SHA256SUMS"; then
echo "::error title=Signature::The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
exit 1
fi
fi
(cd "$bin" && awk -v n="$name" '$2 == n' SHA256SUMS | "${check[@]}")
fi
chmod 0755 "$bin/$name"
mv "$bin/$name" "$bin/swarmetry"
version=$("$bin/swarmetry" --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "::error::The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct cli-version or cli-sha256"
exit 1
fi
echo "$bin" >> "$GITHUB_PATH"
echo "$version"
- name: Run the load test and wait for its verdict
id: run
shell: bash
env:
SWARMETRY_URL: ${{ inputs.url }}
SWARMETRY_TOKEN: ${{ inputs.token }}
PROJECT_ID: ${{ inputs.project-id }}
SCENARIO_ID: ${{ inputs.scenario-id }}
TEST_CONFIG_ID: ${{ inputs.test-config-id }}
ENVIRONMENT_ID: ${{ inputs.environment-id }}
WAIT_TIMEOUT: ${{ inputs.timeout }}
ALLOW_INCONCLUSIVE: ${{ inputs.allow-inconclusive }}
JUNIT_FILE: ${{ inputs.junit-file }}
run: |
if [ -z "$SWARMETRY_TOKEN" ]; then
echo "::error::The input token is empty: pass the token of a service account from a secret"
exit 1
fi
args=(run start --project-id "$PROJECT_ID" --scenario-id "$SCENARIO_ID")
if [ -n "$TEST_CONFIG_ID" ]; then args+=(--test-config-id "$TEST_CONFIG_ID"); fi
if [ -n "$ENVIRONMENT_ID" ]; then args+=(--environment-id "$ENVIRONMENT_ID"); fi
args+=(--note "GitHub Actions $GITHUB_REPOSITORY $GITHUB_REF_NAME ${GITHUB_SHA:0:7}")
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
args+=(--preflight-if-required)
args+=(-y --wait --timeout "$WAIT_TIMEOUT" --stop-on-timeout --junit "$JUNIT_FILE")
# A cancelled workflow signals this shell: pass it on, the command line stops the test it started.
swarmetry "${args[@]}" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do code=0; wait "$pid" || code=$?; done
echo "exit-code=$code" >> "$GITHUB_OUTPUT"
case "$code" in
0) exit 0 ;;
20) echo "::error title=Load test failed::A threshold failed, or the test was stopped by a threshold" ;;
21)
if [ "$ALLOW_INCONCLUSIVE" = true ]; then
echo "::warning title=Load test inconclusive::Nothing failed, but the test cannot be declared passed"
exit 0
fi
echo "::error title=Load test inconclusive::Nothing failed, but the test cannot be declared passed (allow-inconclusive: 'true' lets it pass)"
;;
22) echo "::error title=No verdict::The test has no threshold: add thresholds to its test configuration" ;;
23) echo "::error title=Load test stopped::The test was stopped before its end" ;;
24) echo "::error title=Technical failure::The test failed for a technical reason (error code in the log): run the job again" ;;
25) echo "::error title=Timeout::The test was still running after $WAIT_TIMEOUT and was stopped" ;;
26) echo "::error title=Preflight failed::The preflight the run policy requires did not pass (findings in the log), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "::error title=Token refused::The token was refused or has expired: update the secret" ;;
4) echo "::error title=Refused::The start was refused (error code and hint in the log): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "::error title=Start refused::A rule of your organization refused the start (error code and hint in the log): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "::error title=Cannot start::The test cannot start as configured (error code and hint in the log): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "::error title=Quota reached::A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "::error title=Server unreachable::Check the address of the server and the network of the runner" ;;
130) echo "::error title=Cancelled::The test this job started was stopped" ;;
*) echo "::error title=Load test::The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
- name: Keep the JUnit report
if: always() && inputs.artifact-name != ''
uses: actions/upload-artifact@v7
with:
name: ${{ inputs.artifact-name }}
path: ${{ inputs.junit-file }}
if-no-files-found: ignore
Résultats de test dans GitHub
Les deux fichiers gardent le fichier JUnit comme artefact de l’exécution (swarmetry-junit), téléchargeable depuis la
page de l’exécution, et la ligne de commande écrit le verdict dans le résumé du job. Pour voir chaque seuil comme un
résultat de test dans les pull requests, ajoutez une action qui lit le JUnit XML, par exemple dorny/test-reporter
(avec reporter: java-junit) ou mikepenz/action-junit-report. Elles ne font pas partie des modèles parce qu’elles
viennent d’autres éditeurs : choisissez-en une, fixez sa version comme le demande votre politique, et donnez au job
checks: write comme le dit leur documentation.
GitLab CI/CD
- Dans votre projet, ouvrez Settings > CI/CD > Variables.
- Ajoutez
SWARMETRY_TOKENavec la visibilité Masked and hidden, et cochez Protect variable (recommandé) : seuls les pipelines des branches et tags protégés reçoivent le jeton, et un pipeline lancé sur une autre branche ne peut donc pas s’en servir. Lancez le job sur une branche protégée (la branche par défaut l’est en général) ; sur une autre branche, le job dit que la variable n’est pas définie. - Ajoutez
SWARMETRY_PROJECT_ID,SWARMETRY_SCENARIO_IDetSWARMETRY_TEST_CONFIG_ID. - Ajoutez le job ci-dessous à votre
.gitlab-ci.yml, puis lancez-le depuis Build > Pipelines > New pipeline.
Le fichier JUnit est publié comme rapport de test : l’onglet Tests du pipeline et le résumé des tests de la merge
request montrent le verdict, chaque seuil et chaque vérification. Le job utilise l’image alpine ; sur un exécuteur sans
conteneur (exécuteur shell), retirez la ligne image et la ligne apk add, et installez curl et le client OpenSSH (ssh-keygen) sur la
machine.
# Swarmetry load test gate for GitLab CI/CD: a job.
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/gitlab-ci.yml
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# Add this job to .gitlab-ci.yml (or save it as swarmetry.gitlab-ci.yml and include it with include: local). Then, in
# Settings > CI/CD > Variables:
# - SWARMETRY_TOKEN: the token of a service account (sw_sat_...), Administration > Service accounts. Visibility
# "Masked and hidden", and tick "Protect variable" (recommended): only pipelines of protected branches and tags
# receive the token, so a pipeline of any other branch cannot use it. Run the job on a protected branch;
# - SWARMETRY_PROJECT_ID, SWARMETRY_SCENARIO_ID, SWARMETRY_TEST_CONFIG_ID: the address of the test configuration
# in Swarmetry holds the three ids (/app/projects/<project>/scenarios/<scenario>/configs/<config>).
# The job installs the command line from your server, starts the test with -y (a pipeline has no terminal: -y
# confirms a test that sends load and uses the quotas of your plan), waits for its verdict and publishes the JUnit XML
# in the Tests tab of the pipeline. It fails when the test does not pass; uncomment allow_failure below to let an
# inconclusive test (exit code 21) pass with a warning.
# The command line is checked against the SHA-256 pinned below (SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256, the
# secure choice: the version and the SHA-256 of swarmetry-linux-amd64 on the page Developer access), otherwise against
# SHA256SUMS of your server, itself verified with Swarmetry's release key when one is written below. Downloads are
# https only, TLS 1.2 or later, never redirected to http.
swarmetry-load-test:
stage: test
image: alpine:3.24
timeout: 90m
variables:
SWARMETRY_URL: 'https://swarmetry.io'
SWARMETRY_TIMEOUT: '1h'
# Pinned command line: for example SWARMETRY_CLI_VERSION 'v4.0.0' and SWARMETRY_CLI_SHA256 '<64 hexadecimal
# characters>'. Empty: the file your server serves.
SWARMETRY_CLI_VERSION: ''
SWARMETRY_CLI_SHA256: ''
# Swarmetry's release key, written in by your server (empty: none).
SWARMETRY_RELEASE_SIGNER: ''
rules:
- if: $CI_PIPELINE_SOURCE == "web" # Build > Pipelines > New pipeline
# - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # every commit on the default branch: each test uses your quotas
# allow_failure:
# exit_codes: [21]
script:
- apk add --no-cache curl openssh-keygen
- |
if [ -z "${SWARMETRY_TOKEN:-}" ]; then
echo "The variable SWARMETRY_TOKEN is not set (the token of a service account; a protected variable reaches protected branches only)"
exit 1
fi
case "$(uname -m)" in
x86_64) name=swarmetry-linux-amd64 ;;
aarch64) name=swarmetry-linux-arm64 ;;
*) echo "No command line for the processor $(uname -m)"; exit 1 ;;
esac
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) if [ "$proto" = '=https' ]; then echo "SWARMETRY_URL must be an https address"; exit 1; fi ;;
esac
get() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
mkdir -p .swarmetry
get "$SWARMETRY_URL/cli/files/$name" ".swarmetry/$name"
if [ -n "$SWARMETRY_CLI_VERSION$SWARMETRY_CLI_SHA256" ]; then
if [ -z "$SWARMETRY_CLI_VERSION" ] || [ -z "$SWARMETRY_CLI_SHA256" ]; then
echo "Pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"; exit 1
fi
echo "$(printf '%s' "$SWARMETRY_CLI_SHA256" | tr 'A-F' 'a-f') .swarmetry/$name" | sha256sum -c - || {
echo "Your server serves another command line than the one pinned in this job (its SHA-256: $(sha256sum ".swarmetry/$name" | cut -d ' ' -f 1)). If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
exit 1
}
else
get "$SWARMETRY_URL/cli/files/SHA256SUMS" .swarmetry/SHA256SUMS
if [ -n "$SWARMETRY_RELEASE_SIGNER" ]; then
get "$SWARMETRY_URL/cli/files/SHA256SUMS.sig" .swarmetry/SHA256SUMS.sig
printf '%s\n' "$SWARMETRY_RELEASE_SIGNER" > .swarmetry/allowed_signers
ssh-keygen -Y verify -f .swarmetry/allowed_signers -I swarmetry-cli -n 'cli.swarmetry.io' -s .swarmetry/SHA256SUMS.sig < .swarmetry/SHA256SUMS || {
echo "The signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"; exit 1
}
fi
(cd .swarmetry && awk -v n="$name" '$2 == n' SHA256SUMS | sha256sum -c -)
fi
chmod 0755 ".swarmetry/$name"
mv ".swarmetry/$name" .swarmetry/swarmetry
version=$(.swarmetry/swarmetry --version)
if [ -n "$SWARMETRY_CLI_VERSION" ] && [ "${version##* v}" != "${SWARMETRY_CLI_VERSION#v}" ]; then
echo "The pinned file is $version, not $SWARMETRY_CLI_VERSION: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"; exit 1
fi
echo "$version"
- |
set -- run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID"
if [ -n "${SWARMETRY_TEST_CONFIG_ID:-}" ]; then set -- "$@" --test-config-id "$SWARMETRY_TEST_CONFIG_ID"; fi
if [ -n "${SWARMETRY_ENVIRONMENT_ID:-}" ]; then set -- "$@" --environment-id "$SWARMETRY_ENVIRONMENT_ID"; fi
set -- "$@" --note "GitLab CI $CI_PROJECT_PATH $CI_COMMIT_REF_NAME $CI_COMMIT_SHORT_SHA"
code=0
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
set -- "$@" --preflight-if-required
.swarmetry/swarmetry "$@" -y --wait --timeout "$SWARMETRY_TIMEOUT" --stop-on-timeout --junit swarmetry-junit.xml || code=$?
case "$code" in
0) echo "The test passed" ;;
20) echo "The test failed: a threshold failed, or the test was stopped by a threshold" ;;
21) echo "The test is inconclusive: nothing failed, but it cannot be declared passed (allow_failure exit_codes [21] lets it pass)" ;;
22) echo "The test has no threshold: add thresholds to its test configuration" ;;
23) echo "The test was stopped before its end" ;;
24) echo "Technical failure of the test (error code above): run the job again" ;;
25) echo "The test was still running after $SWARMETRY_TIMEOUT and was stopped" ;;
26) echo "The preflight the run policy requires did not pass (findings above), so the test was not started: fix the scenario, then run the job again" ;;
3) echo "The token was refused or has expired: update the variable SWARMETRY_TOKEN" ;;
4) echo "The start was refused (error code and hint above): a permission of the service account, your plan, an address that is not an allowed target, or the allowed IP ranges of your organization. Do not retry in a loop" ;;
6) echo "A rule of your organization refused the start (error code and hint above): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) echo "The test cannot start as configured (error code and hint above): check the ids, the test configuration, its secrets and datasets" ;;
8) echo "A quota or a limit of your plan is reached. Do not retry in a loop" ;;
11) echo "The server cannot be reached: check SWARMETRY_URL and the network of the runner" ;;
130) echo "Cancelled: the test this job started was stopped" ;;
*) echo "The command line exited with code $code (exit codes in the guide)" ;;
esac
exit "$code"
artifacts:
when: always
expire_in: 30 days
paths:
- swarmetry-junit.xml
reports:
junit: swarmetry-junit.xml
Toute autre CI
Le script shell fonctionne dans toute CI qui lance un shell sous Linux ou macOS : Jenkins, Azure Pipelines, Bitbucket
Pipelines, CircleCI, ou une tâche planifiée. Enregistrez-le dans votre dépôt, donnez au job les variables listées en
haut du fichier (le jeton depuis le coffre de secrets de la CI, par exemple un identifiant lié à SWARMETRY_TOKEN dans
Jenkins), et lancez sh swarmetry-ci.sh. Il lui faut curl, sha256sum ou shasum, et ssh-keygen (OpenSSH 8.1 ou plus récent) une fois une clé de
publication publiée. Il ne se rabat plus sur wget : sur une machine sans curl (une image Alpine Linux minimale, par
exemple), installez-le d’abord (apk add curl). Il réutilise la
ligne de commande déjà installée dans .swarmetry/bin tant que sa somme de contrôle correspond à celle de votre
serveur : une machine qui garde son espace de travail la télécharge une fois par version.
#!/bin/sh
# Swarmetry load test gate for any CI (Jenkins, Azure Pipelines, Bitbucket Pipelines, CircleCI, a cron job...).
# Served by your Swarmetry server, with its address written in:
# https://swarmetry.io/cli/templates/swarmetry-ci.sh
# Guide: "Load tests in a CI pipeline" in the help centre (https://swarmetry.io/app/help/ci).
#
# 1. Downloads the swarmetry command line of this computer from your server and checks it: against the SHA-256 you
# pinned (pinned_version and pinned_sha256 below, the secure choice), otherwise against SHA256SUMS of your server,
# itself verified with Swarmetry's release key when one is written below.
# 2. Starts the test and waits for its verdict. -y confirms the start: a test sends load to your site and uses the
# quotas of your plan, and a pipeline has no terminal to ask you. When the run policy of your organization requires a
# passed preflight, the command line runs it first and starts the test with it (--preflight-if-required).
# 3. Writes the JUnit XML of the test for the test report of your CI, also when the test fails.
# 4. Exits 0 when the test passes, otherwise with the code of the command line (explained in the log).
#
# Set these variables in your CI. Keep the token in the secret store of your CI, never in a file of your repository.
# SWARMETRY_TOKEN (secret) token of a service account, sw_sat_..., Administration > Service accounts
# SWARMETRY_PROJECT_ID project of the test
# SWARMETRY_SCENARIO_ID scenario to run
# SWARMETRY_TEST_CONFIG_ID test configuration (load and thresholds). Recommended: the thresholds decide the verdict.
# The address of a test configuration in Swarmetry holds the three ids:
# /app/projects/<project>/scenarios/<scenario>/configs/<test configuration>
# Optional:
# SWARMETRY_ENVIRONMENT_ID environment of the project (base URL, variables)
# SWARMETRY_TIMEOUT longest wait, then the test is stopped (default 1h)
# SWARMETRY_JUNIT JUnit file (default swarmetry-junit.xml)
# SWARMETRY_SUMMARY summary file, JSON (default swarmetry-summary.json)
# SWARMETRY_NOTE note shown with the test in Swarmetry (default: CI)
# SWARMETRY_ALLOW_INCONCLUSIVE=1 an inconclusive test passes with a warning (default: it fails the job)
# SWARMETRY_ALLOW_NO_VERDICT=1 a test without thresholds passes (default: it fails the job)
# SWARMETRY_INSTALL_DIR folder of the command line (default .swarmetry/bin, reused while its checksum matches)
# SWARMETRY_URL your Swarmetry server (default: the address below; https only)
#
# Pinned command line (recommended): write below the version and the SHA-256 of the file of your CI machine (page
# Developer access of Swarmetry, or its line of SHA256SUMS), and commit this file. The job then runs only that file,
# whatever your server serves; after an upgrade of your server it stops and prints the new SHA-256 to check and pin.
#
# Run it with: sh swarmetry-ci.sh
# POSIX sh (dash, bash, BusyBox). Needs curl, sha256sum or shasum, and ssh-keygen (OpenSSH 8.1 or later) when a
# release key is written below. Linux and macOS. Downloads are https only, TLS 1.2 or later, never redirected to http.
# The token is read from the environment by the command line: this script never prints it.
# The whole script is the function main, called on its last line: a file cut short runs nothing.
main() {
set -eu
SWARMETRY_URL="${SWARMETRY_URL:-https://swarmetry.io}"
# Pinned command line (the secure choice): the version and the SHA-256 of the file of your CI machine, for example
# pinned_version='v4.0.0' and pinned_sha256='<64 hexadecimal characters>'. Empty: the file your server serves.
pinned_version="${SWARMETRY_CLI_VERSION:-}"
pinned_sha256="${SWARMETRY_CLI_SHA256:-}"
# Swarmetry's release key, written in by your server (empty: none): SHA256SUMS is verified with it.
release=''
: "${SWARMETRY_TOKEN:?is not set: add the token of a service account as a secret variable of your CI}"
: "${SWARMETRY_PROJECT_ID:?is not set: the id of the project of the test}"
: "${SWARMETRY_SCENARIO_ID:?is not set: the id of the scenario to run}"
export SWARMETRY_URL SWARMETRY_TOKEN
timeout="${SWARMETRY_TIMEOUT:-1h}"
junit="${SWARMETRY_JUNIT:-swarmetry-junit.xml}"
summary="${SWARMETRY_SUMMARY:-swarmetry-summary.json}"
bin="${SWARMETRY_INSTALL_DIR:-.swarmetry/bin}"
say() { printf 'swarmetry-ci: %s\n' "$1" >&2; }
fail() {
say "$1"
exit 1
}
# 1. The command line of this computer, from your server: the pinned file, or the file of SHA256SUMS (verified
# with the release key when there is one).
case "$(uname -s)" in
Linux) os=linux ;;
Darwin) os=darwin ;;
*) fail "this script runs on Linux and macOS (this system is $(uname -s))" ;;
esac
case "$(uname -m)" in
x86_64 | amd64) arch=amd64 ;;
aarch64 | arm64) arch=arm64 ;;
*) fail "no command line for the processor $(uname -m) (amd64 and arm64 only)" ;;
esac
name="swarmetry-$os-$arch"
files="$SWARMETRY_URL/cli/files"
# https only, TLS 1.2 or later, never a redirect to http (written in by your server; http only for a test server on this computer).
proto='=https'
case "$SWARMETRY_URL" in
https://*) ;;
*) [ "$proto" != '=https' ] || fail "SWARMETRY_URL must be an https address ($SWARMETRY_URL)" ;;
esac
command -v curl >/dev/null 2>&1 || fail "curl is needed to download the command line"
fetch() { curl --proto "$proto" --proto-redir '=https' --tlsv1.2 -fsSL --retry 3 -o "$2" "$1"; }
if command -v sha256sum >/dev/null 2>&1; then
sha256() { sha256sum "$1" | cut -d ' ' -f 1; }
elif command -v shasum >/dev/null 2>&1; then
sha256() { shasum -a 256 "$1" | cut -d ' ' -f 1; }
else
fail "sha256sum or shasum is needed to check the download"
fi
mkdir -p "$bin"
if [ -n "$pinned_version$pinned_sha256" ]; then
[ -n "$pinned_version" ] && [ -n "$pinned_sha256" ] ||
fail "pinned command line: set both SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
sum=$(printf '%s' "$pinned_sha256" | tr 'A-F' 'a-f')
how="pinned $pinned_version, SHA-256 verified"
else
fetch "$files/SHA256SUMS" "$bin/SHA256SUMS" || fail "cannot download $files/SHA256SUMS"
how="checksum verified"
if [ -n "$release" ]; then
command -v ssh-keygen >/dev/null 2>&1 ||
fail "ssh-keygen (OpenSSH 8.1 or later) is needed to verify the signature of SHA256SUMS: install the OpenSSH client"
fetch "$files/SHA256SUMS.sig" "$bin/SHA256SUMS.sig" ||
fail "cannot download $files/SHA256SUMS.sig: your server does not sign its checksums, nothing was run"
printf '%s\n' "$release" >"$bin/allowed_signers"
ssh-keygen -Y verify -f "$bin/allowed_signers" -I swarmetry-cli -n 'cli.swarmetry.io' \
-s "$bin/SHA256SUMS.sig" <"$bin/SHA256SUMS" >/dev/null 2>&1 ||
fail "the signature of SHA256SUMS does not verify with Swarmetry's release key: nothing was run"
how="checksum and signature verified"
fi
sum=$(awk -v n="$name" '$2 == n { print $1 }' "$bin/SHA256SUMS")
[ -n "$sum" ] || fail "$name is not listed in SHA256SUMS of $SWARMETRY_URL"
fi
if [ -x "$bin/swarmetry" ] && [ "$(sha256 "$bin/swarmetry")" = "$sum" ]; then
say "command line already installed in $bin ($how)"
else
fetch "$files/$name" "$bin/$name" || fail "cannot download $files/$name"
got=$(sha256 "$bin/$name")
if [ "$got" != "$sum" ]; then
rm -f "$bin/$name"
[ -z "$pinned_sha256" ] ||
fail "your server serves another command line than the one pinned here (SHA-256 $got, pinned $sum): nothing was run. If your server was upgraded, check the new file on the page Developer access, then update SWARMETRY_CLI_VERSION and SWARMETRY_CLI_SHA256"
fail "the checksum of $name does not match SHA256SUMS: nothing was run (download again; if it fails again, contact Swarmetry support)"
fi
chmod 0755 "$bin/$name"
mv -f "$bin/$name" "$bin/swarmetry"
say "installed $("$bin/swarmetry" --version) in $bin ($how)"
fi
if [ -n "$pinned_version" ]; then
got=$("$bin/swarmetry" --version)
got=${got##* }
[ "${got#v}" = "${pinned_version#v}" ] ||
fail "the pinned file is version $got, not $pinned_version: correct SWARMETRY_CLI_VERSION or SWARMETRY_CLI_SHA256"
fi
# 2. Start the test and wait for its verdict.
set -- run start --project-id "$SWARMETRY_PROJECT_ID" --scenario-id "$SWARMETRY_SCENARIO_ID"
if [ -n "${SWARMETRY_TEST_CONFIG_ID:-}" ]; then set -- "$@" --test-config-id "$SWARMETRY_TEST_CONFIG_ID"; fi
if [ -n "${SWARMETRY_ENVIRONMENT_ID:-}" ]; then set -- "$@" --environment-id "$SWARMETRY_ENVIRONMENT_ID"; fi
if [ "${SWARMETRY_ALLOW_NO_VERDICT:-0}" = 1 ]; then set -- "$@" --allow-no-verdict; fi
# A required preflight (run.preflight_required) is run first, then the test starts with it; exit 26 when it fails.
set -- "$@" --note "${SWARMETRY_NOTE:-CI}" --preflight-if-required
set -- "$@" -y --wait --timeout "$timeout" --stop-on-timeout --junit "$junit" --summary-json "$summary"
# A cancelled job stops the test it started: the CI signals this shell, which passes the signal on to the command
# line (it stops the test, then exits 130).
"$bin/swarmetry" "$@" &
pid=$!
trap 'kill -TERM "$pid" 2>/dev/null || :' INT TERM
code=0
wait "$pid" || code=$?
while kill -0 "$pid" 2>/dev/null; do
code=0
wait "$pid" || code=$?
done
trap - INT TERM
# 3. What the exit code means for this pipeline.
case "$code" in
0) say "the test passed" ;;
20) say "the test failed: a threshold failed, or the test was stopped by a threshold (see the summary above)" ;;
21)
if [ "${SWARMETRY_ALLOW_INCONCLUSIVE:-0}" = 1 ]; then
say "warning: the test is inconclusive (reasons above); SWARMETRY_ALLOW_INCONCLUSIVE=1 lets the job pass"
exit 0
fi
say "the test is inconclusive: nothing failed, but it cannot be declared passed (reasons above). SWARMETRY_ALLOW_INCONCLUSIVE=1 lets it pass"
;;
22) say "the test has no threshold, so no verdict: add thresholds to its test configuration, or set SWARMETRY_ALLOW_NO_VERDICT=1" ;;
23) say "the test was stopped before its end, by a person, an emergency stop or a limit (see the summary above)" ;;
24) say "technical failure of the test (error code above): run the job again; if it fails again, tell your administrator" ;;
25) say "the test was still running after $timeout and was stopped: raise SWARMETRY_TIMEOUT or shorten the test" ;;
26) say "the preflight the run policy requires did not pass (findings above), so the test was not started: fix the scenario, then run the job again" ;;
3) say "the token was refused or has expired: create a token of the service account and update the secret of your CI" ;;
4) say "the start was refused (error code and hint above): a permission of the service account, your plan, an address that is not an allowed target, or your organization's allowed IP ranges. Do not retry in a loop" ;;
6) say "the start was refused by a rule of your organization (error code and hint above): an approval is required (Administration > Approvals), or the required preflight could not be used. Do not retry in a loop" ;;
7) say "the test cannot start as configured (error code and hint above): check the ids, the test configuration, its secrets and datasets" ;;
8) say "a quota or a limit of your plan is reached, or too many requests (error code above). Do not retry in a loop" ;;
11) say "the server cannot be reached: check SWARMETRY_URL and the network of this runner" ;;
130) say "interrupted: the test this job started was stopped" ;;
*) say "the command line exited with code $code (see the exit codes in the guide)" ;;
esac
exit "$code"
}
main "$@"
Ce que répond le job
| Code | Le test | Que faire |
|---|---|---|
| 0 | A réussi | Rien |
| 20 | A échoué : un seuil a échoué, ou le test a été arrêté par un seuil | Ouvrez le test (lien dans le journal) et regardez les seuils en échec |
| 21 | Non concluant : rien n’a échoué, mais il ne peut pas être déclaré réussi (mesures perdues, seuil sans donnée) | Lisez les raisons dans le journal ; voir plus bas pour le laisser passer |
| 22 | Sans verdict : la configuration de test n’a pas de seuil | Ajoutez des seuils, ou laissez-le passer avec --allow-no-verdict (SWARMETRY_ALLOW_NO_VERDICT=1 dans le script shell) |
| 23 | Arrêté avant sa fin, par une personne, un arrêt d’urgence ou une limite | Relancez-le quand la raison a disparu |
| 24 | Échec technique (code d’erreur dans le journal) | Relancez le job ; s’il échoue encore, prévenez votre administrateur |
| 25 | Toujours en cours après SWARMETRY_TIMEOUT, puis arrêté |
Augmentez le délai, ou raccourcissez le test |
| 26 | La pré-vérification que votre organisation exige n’a pas réussi : le test n’a pas été lancé | Lisez ce qu’elle a trouvé dans le journal (et sur la page de la pré-vérification), corrigez le scénario, relancez le job |
| 3 | Le jeton a été refusé ou a expiré | Créez un jeton du compte de service et mettez à jour le secret |
| 4 | Refusé : une permission du compte de service, votre offre, une adresse qui n’est pas une cible autorisée, ou les plages d’adresses IP autorisées de votre organisation | Lisez le code d’erreur et la ligne hint: dans le journal ; ne relancez pas en boucle |
| 6 | Refusé par une règle de votre organisation : une approbation est nécessaire, ou la pré-vérification exigée n’a pas pu être utilisée | Lisez le code d’erreur et la ligne hint: ; voir Contrôles et approbations au lancement ; ne relancez pas en boucle |
| 7 | Le test ne peut pas démarrer tel qu’il est configuré : un identifiant, la configuration de test, un secret ou un jeu de données | Lisez le code d’erreur et la ligne hint:, puis corrigez le test |
| 8 | Un quota ou une limite de votre offre est atteint, ou trop de requêtes | Attendez, ou changez d’offre (page 24) ; ne relancez pas en boucle |
| 11 | Le serveur est injoignable | Vérifiez l’adresse et le réseau de l’exécuteur |
| 130 | Le job a été annulé | Le test qu’il avait lancé a été arrêté |
Tous les codes de la ligne de commande sont listés dans Codes de sortie. Un lancement
refusé affiche son code d’erreur (par exemple Error: approval.required (HTTP 409)) et, pour les refus courants, une
ligne hint: qui dit quoi faire (la ligne de commande écrit en anglais).
Pour garder le rapport du test avec le build, ajoutez --report-file swarmetry-report.pdf à la commande du modèle (il
génère le rapport, qui compte pour un rapport de votre offre, et l’enregistre), puis gardez ce fichier comme artefact,
comme le fichier JUnit.
Laisser passer un test non concluant
Par défaut, un test non concluant fait échouer le job : il n’a pas prouvé que votre site tient la charge. Pour le
laisser passer avec un avertissement, définissez SWARMETRY_ALLOW_INCONCLUSIVE=1 (script shell et workflow GitHub),
allow-inconclusive: 'true' (action composite GitHub), ou décommentez allow_failure: exit_codes: [21] dans le job
GitLab (le job affiche alors un avertissement). Le fichier JUnit montre toujours le verdict comme une erreur, et la page
du test dans Swarmetry dit pourquoi.
Coûts, quotas et refus
- Chaque test lancé par le pipeline compte comme un test lancé depuis l’application : exécutions, heures d’utilisateurs virtuels et les autres quotas de votre offre. Lancez les tests de charge sur les livraisons qui en ont besoin, pas à chaque commit.
- Les modèles ne relancent jamais un lancement refusé. Un quota (code 8), votre offre (code 4) ou une approbation manquante (code 6) refuseront aussi la tentative suivante : relancer en boucle ne fait que remplir les journaux.
- Quand vos administrateurs exigent une approbation au-delà d’une taille de test, un gros test lancé par un pipeline est refusé (code 6) tant que ce lancement n’est pas approuvé. Pour un gros test régulier, une planification, approuvée une fois, est le meilleur outil (Approbation d’une planification).
- Un jeton qui expire pendant un long test fait finir l’attente avec le code 3, alors que le test continue dans Swarmetry. Renouvelez le jeton avec un chevauchement plus long que votre test le plus long (page 31).