Parallel tests support in Polly?
See original GitHub issueDescription
Does Polly support parallel test runs, particularly for the node-http-adapter setup?
I have a node server set up with Polly, which is used by my Cypress tests. Everything works fine running the Cypress tests in series. Running tests in parallel doesn’t seem to be supported though.
Here’s an example:
- Test A & B kicked off in parallel, polly mode = REPLAY (Both recorded previously, and individual or serial replay run works fine)
- Test A starts sending requests to the node server with header “recording-name=TestA”.
- Node server receives request, sets up the polly instance to replay recordings for TestA.
- In parallel, Test B starts sending requests to the node server with header “recording-name=TestB”
In this example, I’d expect to be able to tell Polly that for node requests with header “recording-name=TestA”, use TestA recordings. While for header “recording-name=TestB”, use TestB recordings.
Some ideas I’ve tried include:
- Spinning up multiple polly instances per test (fails because only one node-http-adapter can be active at a time)
- Using the
polly.server.on('request')
andoverrideRecordingName
methods to try and force the recording name before Polly tries to retrieve it.
Neither option seems to work and I’m suspecting the Polly doesn’t support this kind of use case at the moment, but would like to confirm if I’m doing something wrong.
Shareable Source
// Attempted idea:
polly.server
.any()
.filter(_req => {
// Recording name is configured on the new Polly() call
// https://netflix.github.io/pollyjs/#/server/request?id=recordingname
return _req.recordingName !== testName;
})
.on('request', _req => {
console.log('\n\n override recording name', testName);
// Override the recordingName whenever it's different from the original config
// https://netflix.github.io/pollyjs/#/server/request?id=overriderecordingname
_req.overrideRecordingName(testName);
});
Error Message & Stack Trace
N/A
Config
N/A
Dependencies
Copy the @pollyjs dependencies from package.json
:
{
"@pollyjs/adapter-node-http": "^5.1.0",
"@pollyjs/core": "^5.1.0",
"@pollyjs/persister-fs": "^5.0.0",
}
Relevant Links
- Project is not public
Environment
Node.js v12.18.4 darwin 18.7.0 6.14.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
@offirgolan @guyellis Thanks for the inputs. I think I may have missed something in my own understanding. The requests from the NodeJS App to the Service APIs will also still need the test name header, because the http interceptor is just looking at the properties of the http request itself, with no context anywhere of the Express request object. For some reason I was thinking Polly could somehow get this Express request context during the intercept, but that’s not really possible.
I will try updating the implementation of the Service API calls to add this context, and then using the
overrideRecordingName
feature during the request replay.That worked great. Thanks for the inputs and guidance!