/
t3
/
helloworld
Обзор
Документация
Войти
/
t3
/
helloworld
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
src/main.ts
83 строки
2 KB
Ivan Shibkikh
update scenario
07 июл 2026, 11:03
07 июл 2026, 11:03
54b5f80
Код
Авторство
О чём код?
import * as t3 from "./sdk/t3"; interface SetupData { readonly url: string; readonly s3Config: t3.S3Config; } interface AgentData { readonly size: number; } interface InitData { readonly http: t3.HttpClient; } interface RunCtx { readonly iteration: number; readonly userId: number; readonly init: InitData; } const reqs = t3.Counter("http_requests"); const file_size = t3.Gauge("file_size"); // run once before the test export function setup(): SetupData { const data = { url: "s3://localhost/api/v1/tmp/users.txt", s3Config: { endpoint: "https://localhost/api/v1", accessKey: "", secretKey: "", region: "ru-west1", useSSL: true, insecureSkipVerify: true, } } console.log("setup called:", JSON.stringify(data)) return data } export function init_agent(setup: SetupData): AgentData { const f = t3.s3.download(setup.url, setup.s3Config); if (f.size === 0) { throw new Error("s3 file has 0 size") } const content = f.text() file_size.set(f.size) return { size: f.size } } // run once for each vuser before the test export function init(_: SetupData, agent: AgentData): InitData { const http = t3.http.newClient({ baseURL: "https://ya.ru", headers: { "Authorization": "Bearer token123" }, insecureSkipVerify: false, timeoutMs: 30000, }); return { http }; } // main user iteration function export default function (ctx: RunCtx) { const { http } = ctx.init; const resp = http.fetch("/users"); console.log(resp.status); // 200 console.log(resp.responseTime.ttfb); // ms до первого байта console.log(resp.responseTime.total); // ms до последнего байта console.log(resp.text()); // тело как строка reqs.add(1); } // run once after the test export function teardown(data: SetupData) { console.log("teardown called:", JSON.stringify(data)) }