GrabThuy NguyenProblem & solution
Loki, a Dynamic Mock Server for HTTP/TCP Testing
Summary
Grab built Loki, a dynamic mock server written in Golang that simulates backend services on local developer machines and CI pipelines. Mobile app testing previously suffered from heavy dependencies on complex, brittle staging environments and interconnected services communicating over HTTP, HTTPS, and TCP. Loki handles both HTTP and TCP traffic on distinct ports while exposing a unified RESTful API to manage test expectations. It provides runtime flexibility through sandboxed JavaScript execution, configurable request sequence ordering, and an in-memory cron scheduler for TCP push messages. Adopting Loki decoupled mobile releases from staging stability, improving delivery cycles and enabling automated UI testing with Espresso and XCUITest.
Context
End-to-end mobile app testing at Grab faced significant friction due to heavy dependencies on backend services, staging downtime, data corruption, and complex multi-app business flows spanning HTTP and TCP.
Approach / What changed
Grab developed Loki, a containerized Golang mock server with pluggable storage backends (MySQL, Redis, or in-memory cache) that supports dynamic JavaScript injection, sequenced HTTP responses, and an in-memory cron system to push scheduled TCP events.
Takeaways
Mocking TCP required handling long-running client-server connections, configurable request delimiters for JSON deserialization, and unsolicited push messages via an in-memory cron scheduler.
Dynamic responses can be computed at runtime using an in-house JavaScript execution library running inside an isolated sandbox.
The httpTimesAndOrder API enables developers to configure ordered response state transitions on the same endpoint to simulate sequential lifecycle changes like ride booking stages.
Source and freshness
- Source
- engineering.grab.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.