MCPcopy Create free account
hub / github.com/avoidwork/tenso / runLoadTest

Function runLoadTest

benchmarks/load-test.js:122–174  ·  view source on GitHub ↗

* Runs a load test with autocannon

(options)

Source from the content-addressed store, hash-verified

120 * Runs a load test with autocannon
121 */
122async function runLoadTest (options) {
123 const {
124 url,
125 title,
126 connections = 10,
127 duration = 10,
128 method = "GET",
129 body,
130 headers,
131 ...otherOptions
132 } = options;
133
134 console.log(`\n🚀 ${title}`);
135 console.log("-".repeat(50));
136 console.log(`URL: ${url}`);
137 console.log(`Method: ${method}`);
138 console.log(`Connections: ${connections}`);
139 console.log(`Duration: ${duration}s`);
140
141 const result = await autocannon({
142 url,
143 connections,
144 duration,
145 method,
146 body: body ? JSON.stringify(body) : undefined,
147 headers: {
148 "Content-Type": "application/json",
149 ...headers
150 },
151 ...otherOptions
152 });
153
154 // Print results
155 console.log("\n📊 Results:");
156 console.log(` Requests/sec: ${result.requests.average.toFixed(2)}`);
157 console.log(` Latency avg: ${result.latency.average.toFixed(2)}ms`);
158 console.log(` Latency p99: ${result.latency.p99.toFixed(2)}ms`);
159 console.log(` Throughput: ${(result.throughput.average / 1024 / 1024).toFixed(2)} MB/sec`);
160 console.log(` Total requests: ${result.requests.total}`);
161 console.log(` Total bytes: ${(result.throughput.total / 1024 / 1024).toFixed(2)} MB`);
162 console.log(` Error rate: ${(result.errors / result.requests.total * 100).toFixed(2)}%`);
163
164 if (result.errors > 0) {
165 console.log(` ⚠️ Errors: ${result.errors}`);
166 if (result["1xx"] > 0) console.log(` 1xx: ${result["1xx"]}`);
167 if (result["2xx"] > 0) console.log(` 2xx: ${result["2xx"]}`);
168 if (result["3xx"] > 0) console.log(` 3xx: ${result["3xx"]}`);
169 if (result["4xx"] > 0) console.log(` 4xx: ${result["4xx"]}`);
170 if (result["5xx"] > 0) console.log(` 5xx: ${result["5xx"]}`);
171 }
172
173 return result;
174}
175
176/**
177 * Basic load tests

Callers 9

basicLoadTestsFunction · 0.85
postLoadTestsFunction · 0.85
formatLoadTestsFunction · 0.85
rateLimitLoadTestsFunction · 0.85
stressTestsFunction · 0.85
parameterizedTestsFunction · 0.85
mixedWorkloadTestsFunction · 0.85
hypermediaEnabledTestsFunction · 0.85
hypermediaDisabledTestsFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected