Skip to content

Add k6 and Socket.IO load tests for API and WebSocket endpoints (#60) - #85

Open
BigManly4 wants to merge 2 commits into
SwiftChainn:mainfrom
BigManly4:feat/load-testing
Open

Add k6 and Socket.IO load tests for API and WebSocket endpoints (#60)#85
BigManly4 wants to merge 2 commits into
SwiftChainn:mainfrom
BigManly4:feat/load-testing

Conversation

@BigManly4

Copy link
Copy Markdown

closes #60

Summary

  • Add k6 load test scenarios for the REST API: auth (login/register) and
    delivery CRUD + status update endpoints under /api/v1.
  • Add a Socket.IO load testing harness (load-tests/socket-load) built on
    the real socket.io-client library, since neither k6 nor Artillery ship
    a maintained engine that speaks the Socket.IO protocol. It ramps up N
    concurrent simulated driver connections, authenticates each via the
    real /api/v1/auth/login endpoint, joins a delivery room, and emits
    driver_location_update on an interval, reporting connect/ack success
    rates at the end of the run.
  • Add scripts/seedLoadTestData.ts, which seeds real User and Delivery
    documents through the application's own Mongoose models before a run.
    No inline mocks or hardcoded response data are used anywhere in the
    suite; every scenario exercises the real HTTP/WebSocket API against
    that seeded data.
  • Both the k6 scenarios and the WebSocket harness follow a
    controller -> service -> model layering (documented in
    load-tests/README.md).

Required fix to make WebSocket testing possible

src/sockets/connectionHandler.ts (initializeSocketServer) - the module
that registers the location-tracking Socket.IO gateway - was never
attached to the HTTP server in src/server.ts. The app only ever called
app.listen(...) directly, so the WebSocket gateway was dead code with no
way to connect to it. This PR updates server.ts to use
http.createServer(app) + initializeSocketServer(httpServer), with a
graceful shutdown call to shutdownSocketServer. No behavior of the
gateway itself was changed.

Also fixed: pre-existing build failure

src/controllers/deliveryController.ts contained two unrelated modules
concatenated together (apparent bad merge), causing duplicate
Request/Response identifiers and a DeliveryStatus type mismatch that
made tsc/pnpm build fail on main independent of this PR. Split the CRUD
functions into deliveryCrudController.ts and updated the import in
routes/delivery.ts. Neither route file is mounted in routes/index.ts, so
this is a compile-only fix with no behavior change.

Known pre-existing gaps (left out of scope)

  • src/routes/deliveryRoutes.ts (/eta) and src/routes/stellar.routes.ts
    are not mounted in src/routes/index.ts, so those endpoints 404 and are
    excluded from the load test scenarios.

How to run

See load-tests/README.md. In short:
cd load-tests && npm install && cp .env.example .env
npm run seed
npm run test:api:auth && npm run test:api:deliveries
npm run test:ws

Test plan

  • tsc --noEmit passes for load-tests/ and the main src/ project
  • eslint passes for all changed/added files
  • npm run seed successfully creates driver/customer/delivery fixtures
  • k6 auth and delivery scenarios complete with thresholds met
    (http_req_failed rate < 1%, p95 < 500ms)
  • WebSocket harness completes with >= 95% successful connections
  • Screenshot/log output of a completed run attached below

src/controllers/deliveryController.ts contained two unrelated modules
concatenated together (the ETA controller and a separate CRUD
controller with its own Request/Response import), causing duplicate
identifier errors and a DeliveryStatus type mismatch that made
tsc/pnpm build fail. Split the CRUD functions out into
deliveryCrudController.ts and updated src/routes/delivery.ts to import
from it. Neither route file is currently mounted in routes/index.ts,
so this has no effect on live behavior - it only makes the project
compile.
Add k6 scenarios covering auth and delivery REST endpoints, plus a
socket.io-client based harness for load-testing the real-time location
gateway, both driven by real seeded MongoDB data instead of mocks.

Also attach the previously unwired Socket.IO gateway
(initializeSocketServer) to the HTTP server in server.ts, since it was
dead code and there was otherwise no running WebSocket endpoint to test.
@drips-wave

drips-wave Bot commented Jul 26, 2026

Copy link
Copy Markdown

@BigManly4 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend: Write load tests using Artillery or k6 for WebSocket and API endpoints

1 participant