CtripPaymentRepeater: Reducing Regression Test Effort with Traffic Capture and Replay
The article introduces CtripPaymentRepeater, a Java‑based system that captures real traffic from a stable version, manages it as test cases, and replays it against new releases to automatically detect regressions while minimizing manual effort and ensuring data safety.
Regression testing becomes increasingly costly as applications grow in complexity; traditional full‑suite regression may require thousands of test cases to find a single defect. CtripPaymentRepeater (CPR) addresses this by capturing traffic from a stable version, storing it, and replaying it against a candidate release for automated comparison.
CPR Goals
Achieve high coverage using large amounts of real traffic.
Manage recorded traffic as reusable automated test cases.
Support mock handling for sub‑calls to avoid dirty data.
Validate sub‑call results during replay.
Reduce manual testing effort.
The basic process consists of three steps: traffic collection from a stable server, traffic analysis and case selection in the CPR console, and replay/comparison against the new version.
Architecture
CPR is split into two main components:
CPR (CtripPaymentRepeater) Component – built on the open‑source jvm‑sandbox, containing two sub‑modules: CPRRecord: records request/response data and uploads it to storage. CPRReplay: replays recorded traffic, sends results to the comparison service, and highlights differences.
CPRConsole Component – provides configuration management, storage, replay, and comparison services.
Processing Flow
During recording, the DefaultEventListener intercepts all events. It distinguishes between recording and replay based on the trace ID, assembles invocation information (identity, request, response, throwable), and stores it in a cache.
For replay, the system deserializes the recorded data, reconstructs the original request, and dispatches it via the appropriate plugin repeater. Results are captured, compared with the recorded baseline, and reported back to the console.
Mock Handling
When a sub‑call is identified as a replay, the processor.doMock method creates a MockRequest , selects a mock strategy, and executes it. Depending on the MockResponse.action , the framework may skip the call, throw an exception, or return a mocked result, using ProcessControlException to short‑circuit the original call.
public void doMock(BeforeEvent event, Boolean entrance, InvokeType type) throws ProcessControlException {
// Obtain replay context
RepeatContext context = RepeatCache.getRepeatContext(Tracer.getTraceId());
if (!skipMock(event, entrance, context) && context != null && context.getMeta().isMock()) {
try {
final MockRequest request = MockRequest.builder()
.argumentArray(this.assembleRequest(event))
.event(event)
.identity(this.assembleIdentity(event))
.meta(context.getMeta())
.recordModel(context.getRecordModel())
.traceId(context.getTraceId())
.repeatId(context.getMeta().getRepeatId())
.index(SequenceGenerator.generate(context.getTraceId()))
.type(type)
.build();
final MockResponse mr = StrategyProvider.instance()
.provide(context.getMeta().getStrategyType())
.execute(request);
switch (mr.action) {
case SKIP_IMMEDIATELY:
break;
case THROWS_IMMEDIATELY:
ProcessControlException.throwThrowsImmediately(mr.throwable);
break;
case RETURN_IMMEDIATELY:
ProcessControlException.throwReturnImmediately(assembleMockResponse(event, mr.invocation));
break;
default:
ProcessControlException.throwThrowsImmediately(new RepeatException("invalid action"));
}
} catch (ProcessControlException pce) {
throw pce;
} catch (Throwable throwable) {
ProcessControlException.throwThrowsImmediately(new RepeatException("unexpected code snippet here.", throwable));
}
}
}The system also integrates with Ctrip's internal security platform to protect data in transit and at rest, ensuring compliance with information security policies.
Conclusion
CPR demonstrates how traffic‑driven recording and replay can dramatically cut regression testing effort while maintaining high confidence in release quality, and it can be extended to production data comparison or a standalone mock platform.
Ctrip Technology
Official Ctrip Technology account, sharing and discussing growth.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.