// What the load tests share. Each virtual user is a listener of its own, signed in by name with // the header the scratch daemon trusts from 127.0.0.1, as production trusts Cloudflare Access's. export const BASE = __ENV.BASE; export const USERS = Number(__ENV.USERS || 100); export const FEEDS = Number(__ENV.FEEDS || 1500); // Each generated feed has this many items; see run.ts. export const ITEMS = 20; import type { RefinedResponse, ResponseType } from 'k6/http'; /// The parts of ipx's answers the scripts read (web/src/types.ts has them whole). export type Enclosure = { id: number, path: string | null }; export type Entry = { feed_id: string, guid: string, duration: number | null, position: number, read: boolean, enclosures: Enclosure[] }; export type ListPage = { total: number, entries: Entry[] }; export type Feed = { id: string }; /// An answer's JSON as the API sends it: k6 types it as any JSON at all. export const body = (r: RefinedResponse) => r.json() as unknown as T; export const as = (name: string, tag: string) => ({ headers: { 'X-Load-User': name, 'Content-Type': 'application/json' }, tags: { name: tag }, }); /// The listener this virtual user is, one of the hundred run.ts seeded, thirty feeds each. export const me = () => `load-${(__VU - 1) % USERS}`; export const pick = (a: T[]): T => a[Math.floor(Math.random() * a.length)]; /// A p95 budget, in ms, for whichever database the daemon is on (run.ts --postgres): SQLite reads /// a file beside the daemon, Postgres answers over the network, and each is quicker at something. export const p95 = (sqlite: number, postgres: number) => [`p(95)<${__ENV.DB === 'postgres' ? postgres : sqlite}`]; export const feedId = (n: number) => `gen-${String(n).padStart(4, '0')}`;