mcpField
T
testing-perf

testing-perf

github.com/yonatangrossテスト・品質299114 回インストール今日更新
リポジトリ

testing-perf について

テストエンジニアや開発者向けの性能・負荷テストガイドで、k6、Locust、pytest の実行最適化を扱います。テスト種別、並列実行、データベース分離、チェックリストのパターンを提供します。

主な機能

  1. 01k6 のしきい値、ステージ、カスタム指標
  2. 02Locust による負荷テストパターン
  3. 03負荷・ストレス・スパイク・ソークテストの種別
  4. 04pytest-xdist の並列実行とマーカー
  5. 05並列テスト用のワーカー別データベース分離
  6. 06性能テストと pytest のチェックリスト

活用シーン

  1. 01API の段階的な負荷テストを設定する
  2. 02想定トラフィックに応じたテスト種別を選ぶ
  3. 03pytest-xdist でテストスイートを高速化する
  4. 04並列テストのワーカー間でデータベースを分離する

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/yonatangross/orchestkit --skill testing-perf

インストール後、Claude Code で/testing-perfを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

test-cases.json
checklists/
performance-checklist.md
pytest-production-checklist.md
references/
custom-plugins.md
k6-patterns.md
xdist-parallel.md
rules/
_sections.md
execution.md
perf-k6.md
perf-locust.md
perf-types.md
pytest-execution.md
pytest-plugins.md
scripts/
test-case-template.md

詳細

パフォーマンス/負荷テストのパターン

パフォーマンステスト、負荷テスト、pytest の実行最適化に特化したスキルです。k6、Locust、pytest-xdist による並列実行、カスタムプラグイン、テスト種別の分類を扱います。

クイックリファレンス

分野ファイル目的
k6 負荷テストrules/perf-k6.mdしきい値、ステージ、カスタムメトリクス、CI 連携
Locust テストrules/perf-locust.mdPython の負荷テスト、タスクの重み付け、認証フロー
テスト種別rules/perf-types.md負荷、ストレス、スパイク、ソークテストのパターン
実行rules/execution.mdカバレッジレポート、並列実行、失敗分析
Pytest マーカーrules/pytest-execution.mdカスタムマーカー、xdist 並列実行、ワーカーの分離
Pytest プラグインrules/pytest-plugins.mdファクトリーフィクスチャ、プラグインフック、アンチパターン
k6 のパターンreferences/k6-patterns.md段階的な負荷増加、認証済みリクエスト、テスト種別
xdist 並列実行references/xdist-parallel.md分散モード、ワーカーの分離、CI 設定
カスタムプラグインreferences/custom-plugins.mdconftest プラグイン、インストール可能なプラグイン、フックのリファレンス
パフォーマンスチェックリストchecklists/performance-checklist.md計画、セットアップ、メトリクス、負荷パターン、分析
Pytest チェックリストchecklists/pytest-production-checklist.md設定、マーカー、並列実行、フィクスチャ、CI/CD
テストテンプレートscripts/test-case-template.mdテストケースのドキュメント全体のテンプレート

k6 クイックスタート

しきい値と段階的な負荷増加を設定して、負荷テストを準備します。

import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 20 },  // Ramp up
    { duration: '1m', target: 20 },   // Steady state
    { duration: '30s', target: 0 },   // Ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],  // 95th percentile under 500ms
    http_req_failed: ['rate<0.01'],    // Less than 1% error rate
  },
};

export default function () {
  const res = http.get('http://localhost:8000/api/health');
  check(res, {
    'status is 200': (r) => r.status === 200,
    'response time < 200ms': (r) => r.timings.duration < 200,
  });
  sleep(1);
}

実行:k6 run --out json=results.json tests/load/api.js

k6 v1.0 以降(2025 年 5 月)— 変更点
  • TypeScript ネイティブ対応:k6 run tests/load/api.ts — コンパイルの手順は不要です。
  • 拡張機能の自動プロビジョニング:k6 run が必要な拡張機能を自動的に取得します。ほとんどのワークフローで、手動の xk6 build は不要になりました。
  • ブラウザーモジュールのインポート:import browser from 'k6/browser' — 以前の k6/experimental/browser パスは v0.52 以降で削除されました。/experimental/ を使用する生成コードは失敗します。
  • OTLP 出力を標準搭載:k6 run --out experimental-opentelemetry=... — 結果をトレースバックエンドに直接ストリーミングします。
import http from 'k6/http'
import browser from 'k6/browser'
import { check } from 'k6'

export const options = { vus: 5, duration: '30s' }

export default async function () {
  const page = await browser.newPage()
  await page.goto('https://example.com')
  check(page, { 'title present': async p => (await p.title()).length > 0 })
  await page.close()
}

パフォーマンステストの種別

種別時間VU 数目的使用タイミング
負荷5~10 分想定トラフィック通常条件を検証するリリースごと
ストレス10~20 分想定の 2~3 倍限界点を見つけるリリース前
スパイク5 分突発的な 10 倍の急増オートスケーリングをテストするイベント前
ソーク4~12 時間通常負荷メモリリークを検出する毎週/毎晩

pytest の並列実行

pytest-xdist でテストスイートを高速化します。

# pyproject.toml
[tool.pytest.ini_options]
addopts = ["-n", "auto", "--dist", "loadscope"]
markers = [
    "slow: marks tests as slow",
    "smoke: critical path tests for CI/CD",
]
# Run with parallel workers and coverage
pytest -n auto --dist loadscope --cov=app --cov-report=term-missing --maxfail=3

# CI fast path — skip slow tests
pytest -m "not slow" -n auto

# Debug mode — single worker
pytest -n 0 -x --tb=long

ワーカーデータベースの分離

データベースを使うテストを並列実行する場合は、ワーカーごとに分離します。

@pytest.fixture(scope="session")
def db_engine(worker_id):
    db_name = f"test_db_{worker_id}" if worker_id != "master" else "test_db"
    engine = create_engine(f"postgresql://localhost/{db_name}")
    yield engine
    engine.dispose()

主な目標値

メトリクス目標ツール
p95 応答時間< 500msk6
p99 応答時間< 1000msk6
エラー率< 1%k6 / Locust
ビジネスロジックのカバレッジ90%pytest-cov
クリティカルパスのカバレッジ100%pytest-cov

選択ガイド

シナリオ推奨
JavaScript/TypeScript チーム負荷テストには k6
Python チーム負荷テストには Locust
CI のしきい値が必要k6(しきい値のサポートを標準搭載)
分散テストが必要Locust(分散モードを標準搭載)
テストスイートの実行が遅いpytest-xdist と -n auto
並列実行でテストが不安定フィクスチャをグループ化する --dist loadscope
DB 負荷の高いテストworker_id を使ってワーカーごとに分離したデータベース

関連スキル

  • ork:testing-unit — 単体テストのパターン、pytest フィクスチャ
  • ork:testing-e2e — Playwright によるエンドツーエンドのパフォーマンステスト
  • ork:performance — Core Web Vitals と最適化のパターン

コメント