MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / chunkedRequestBurstSmoke

Method chunkedRequestBurstSmoke

Tests/Libraries/Http/HttpStressTest.cpp:221–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

219 SC_TEST_EXPECT(httpServer.getConnections().getNumActiveConnections() <= 1);
220 SC_TEST_EXPECT(eventLoop.close());
221}
222
223void SC::HttpStressTest::chunkedRequestBurstSmoke()
224{
225 constexpr int NumRequests = 32;
226 constexpr int NumConnections = 4;
227 constexpr int RequestSlices = 2;
228 constexpr int HeaderBytes = 8 * 1024;
229 constexpr int StreamBytes = 1024;
230 constexpr size_t ExpectedBodyBytes = 32;
231 const uint16_t serverPort = report.mapPort(6211);
232
233 AsyncEventLoop eventLoop;
234 SC_TEST_EXPECT(eventLoop.create());
235
236 using HttpConnectionType = HttpAsyncConnection<RequestSlices, RequestSlices, HeaderBytes, StreamBytes>;
237
238 HttpConnectionType connections[NumConnections];
239 HttpAsyncServer httpServer;
240 SC_TEST_EXPECT(httpServer.init(Span<HttpConnectionType>(connections)));
241 SC_TEST_EXPECT(httpServer.start(eventLoop, "127.0.0.1", serverPort));
242
243 struct RequestSlot
244 {
245 void onData(AsyncBufferView::ID bufferID)
246 {
247 SC_ASSERT_RELEASE(connection != nullptr);
248
249 Span<const char> data;
250 SC_ASSERT_RELEASE(connection->request.getReadableStream().getBuffersPool().getReadableData(bufferID, data));
251
252 const size_t index = connection->getConnectionID().getIndex();
253 SC_ASSERT_RELEASE(index < NumConnections);
254 bodyBytes[index] += data.sizeInBytes();
255 SC_ASSERT_RELEASE(connection->request.consumeBodyBytes(data.sizeInBytes()));
256 }
257
258 void onEnd()
259 {
260 SC_ASSERT_RELEASE(connection != nullptr);
261 if (responded)
262 {
263 return;
264 }
265 responded = true;
266 (void)connection->request.getReadableStream().eventData.removeListener<RequestSlot, &RequestSlot::onData>(
267 *this);
268 (void)connection->request.getReadableStream().eventEnd.removeListener<RequestSlot, &RequestSlot::onEnd>(
269 *this);
270
271 const size_t index = connection->getConnectionID().getIndex();
272 test->recordExpectation("chunked stress connection index", index < NumConnections);
273 test->recordExpectation("chunked stress decoded body size", bodyBytes[index] == expectedBodyBytes);
274 test->recordExpectation("chunked stress response", connection->response.sendEmpty(200));
275 (*ended)++;
276 }
277
278 HttpStressTest* test = nullptr;

Callers

nothing calls this directly

Calls 13

mapPortMethod · 0.80
getResponseMethod · 0.80
recordExpectationMethod · 0.80
sendRawMethod · 0.80
formatFunction · 0.50
createMethod · 0.45
initMethod · 0.45
startMethod · 0.45
stopMethod · 0.45
viewMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected