martian icon indicating copy to clipboard operation
martian copied to clipboard

HTTP/S reponse record and replay

Open bramhaghosh opened this issue 9 years ago • 7 comments

Provide support for HTTP/S response record and replay

Users have asked for the capability to record responses from external services, and then to use those responses as a mechanism to stub out the external service during the execution of a test run.

Proposed Record Mode Workflow

  1. Put Martian into RECORD mode
  2. Instruct Martian to record responses to requests that match a provided keyGen() function.
  3. Provide Martian with the path to the db in which to save responses (bolt?).
  4. As requests that match the provided keyGen() come across, Martian captures the response that comes back from the HTTP roundtrip.
  5. For each response for request that matches the keyGen(), Martian adds a header with a known name (X-Martian-Key) where the value is a string representation of the output of keyGen().
  6. While in RECORD mode, any response modifiers will be applied before capture, maybe. Depends on where on the stack the record/replay modifier lives.
  7. Martian holds the responses in memory, and when Martian leaves RECORD mode, the responses are written to the filesystem to the provided path and filename.

Proposed Replay Mode Workflow

  1. Put Martian into REPLAY mode and tell it where the response cache db and the keyGen() used in RECORD mode
  2. Martian parses the response cache db and holds it in memory
  3. As requests that match the provided keyGen() come across, Martian grabs any matching response from the cache db, deletes the X-Martian-Key header, and returns the cached response.
  4. Martian applies any other modifiers on the stack - this is where you'd want to put modifiers that remove "dynamic" headers (datetime, etc.)
  5. Martian returns the modified cached response.

bramhaghosh avatar Feb 26 '16 00:02 bramhaghosh

Is this still planned? I think it'd be great for testing.

bootstraponline avatar Jan 19 '17 18:01 bootstraponline

Yes - it's under active development.

Keep an eye out for it this quarter.

On Thu, Jan 19, 2017 at 10:19 AM bootstraponline [email protected] wrote:

Is this still planned? I think it'd be great for testing.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/google/martian/issues/75#issuecomment-273855099, or mute the thread https://github.com/notifications/unsubscribe-auth/AADI-Uz9eRpLjpAmFBCTNEWdB0lJVK6hks5rT6kegaJpZM4HjVnu .

bramhaghosh avatar Jan 19 '17 19:01 bramhaghosh

Awesome! Thanks for the info.

bootstraponline avatar Jan 19 '17 19:01 bootstraponline

Is there an updated ETA?

bootstraponline avatar Apr 26 '17 14:04 bootstraponline

How should the keyGen() function be passed in? In the JSON config? Or in another modifier before it?

hueich avatar Sep 09 '17 20:09 hueich

An initial implementation is being worked on in the "caching" branch, for those interested.

hueich avatar Oct 15 '17 06:10 hueich

It'd be helpful to demo a simple use case of record/playback for Java using okhttp. If this can be used as a wiremock alternative for Android testing, that'd be excellent.

bootstraponline avatar Oct 16 '17 00:10 bootstraponline