airbnb / okreplay

📼 Record and replay OkHttp network interaction in your tests.
Apache License 2.0
781 stars 71 forks source link

Sequential request matching with rules #73

Open colintheshots opened 6 years ago

colintheshots commented 6 years ago

It seems like it should be possible to write a sequential replay test where I can match rules, but record multiple interactions per rule set. This would help by not enforcing strict ordering of requests like a pure sequential test, but would allow repeated queries to an endpoint with differing responses each time.

It seems like the best behavior for this type of test would be to record rules to tape as long as READ_WRITE is active and then parse the rules when READ_ONLY is active. You would consume the rules sequentially until only one is left and then reuse it for all future requests which match that rule set.

I'm not sure how hard this would be. I may take a look at implementing it.

krpiotrek commented 6 years ago

Hi @colintheshots, have you been working on that?

jraska commented 6 years ago

Hi, I had the same issue and I implemented some workaround with adding extra query parameter for OkReplay to record the requests separately, but not enforcing strict ordering of other requests.

Check here: https://github.com/jraska/github-client/blob/master/client/src/androidTest/java/com/jraska/github/client/http/CustomOkReplayInterceptor.kt

One interceptor adds the parameter before OkReplayInterceptor and other one removes it straight after to isolate it only for OkReplay. I had to extend OkReplayIntercptor to capture the methods start and stop, to clear the internal mappings whilst switching tapes.

Works for me, let me know what you think.