smoke.js (1745B)
1 /** 2 * Smoke test — single VU, single iteration, verifies all key endpoints respond correctly. 3 * 4 * Run: 5 * k6 run k6/smoke.js 6 * BASE_URL=http://staging:8080 k6 run k6/smoke.js 7 */ 8 9 import http from 'k6/http'; 10 import { check } from 'k6'; 11 import { BASE_URL } from './config.js'; 12 13 export const options = { 14 vus: 1, 15 iterations: 1, 16 thresholds: { 17 checks: ['rate==1.0'], // every check must pass in smoke mode 18 }, 19 }; 20 21 export default function () { 22 // 1. Health check 23 { 24 const res = http.get(`${BASE_URL}/healthz`); 25 check(res, { 26 'healthz: status 200': (r) => r.status === 200, 27 'healthz: body is ok': (r) => r.body.trim() === 'ok', 28 }); 29 } 30 31 // 2. Federation-ok (simple status endpoint) 32 { 33 const res = http.get(`${BASE_URL}/api/federation/federation-ok?server_name=matrix.org`); 34 check(res, { 35 'federation-ok: status 200': (r) => r.status === 200, 36 'federation-ok: body is GOOD or BAD': (r) => 37 r.body.trim() === 'GOOD' || r.body.trim() === 'BAD', 38 }); 39 } 40 41 // 3. Full federation report 42 { 43 const res = http.get(`${BASE_URL}/api/federation/report?server_name=matrix.org`, { 44 timeout: '30s', 45 }); 46 check(res, { 47 'federation/report: status 200': (r) => r.status === 200, 48 'federation/report: has FederationOK field': (r) => { 49 try { 50 const body = JSON.parse(r.body); 51 return typeof body.FederationOK === 'boolean'; 52 } catch { 53 return false; 54 } 55 }, 56 }); 57 } 58 59 // 4. Metrics endpoint (if Prometheus is enabled; gracefully skip if 404) 60 { 61 const res = http.get(`${BASE_URL}/metrics`); 62 check(res, { 63 'metrics: status 200 or 404': (r) => r.status === 200 || r.status === 404, 64 }); 65 } 66 }