/ opencodehub / tests / load / k6-smoke.js
Swadhin Biswas test(qa): add e2e, integration, unit, and load coverage · 3/6/2026
1c29e63
48 lines · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * k6 Smoke Test — basic sanity check under minimal load
 * Run: k6 run tests/load/k6-smoke.js
 */
import { check, sleep } from "k6";
import http from "k6/http";

const BASE_URL = __ENV.BASE_URL || "http://localhost:4321";

export const options = {
  stages: [
    { duration: "30s", target: 5 },
    { duration: "1m", target: 5 },
    { duration: "30s", target: 0 },
  ],
  thresholds: {
    http_req_duration: ["p(95)<500", "p(99)<1000"],
    http_req_failed: ["rate<0.01"],
  },
};

export default function () {
  // 1. Homepage
  const homeRes = http.get(`${BASE_URL}/`);
  check(homeRes, {
    "homepage status 200": (r) => r.status === 200,
    "homepage time < 500ms": (r) => r.timings.duration < 500,
  });

  sleep(1);

  // 2. Health endpoint
  const healthRes = http.get(`${BASE_URL}/api/health`);
  check(healthRes, {
    "health status 200": (r) => r.status === 200,
  });

  sleep(0.5);

  // 3. Explore/public repos
  const exploreRes = http.get(`${BASE_URL}/explore`);
  check(exploreRes, {
    "explore status 200": (r) => r.status === 200,
  });

  sleep(1);
}