question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parallel tests support in Polly?

See original GitHub issue

Description

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:

  1. Test A & B kicked off in parallel, polly mode = REPLAY (Both recorded previously, and individual or serial replay run works fine)
  2. Test A starts sending requests to the node server with header “recording-name=TestA”.
  3. Node server receives request, sets up the polly instance to replay recordings for TestA.
  4. 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') and overrideRecordingName 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:closed
  • Created 3 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
patrickshaughnessycommented, Jan 26, 2021

@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.

0reactions
patrickshaughnessycommented, Feb 13, 2021

That worked great. Thanks for the inputs and guidance!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Performance - Polly - LLVM
For the parallel runs we used Polly to expose parallelism and to add calls to an OpenMP runtime library. With OpenMP we can...
Read more >
Parallelize tasks using polly - Stack Overflow
Parallelize tasks using polly ... I have a polly policy : var policy = Policy. ... Will this be called in parallel and...
Read more >
Parallel test suites - Percy Docs
Parallelism is a common way to speed up test suites by running multiple tests concurrently and then combining results at the end. Percy...
Read more >
Python Examples - Amazon Polly - AWS Documentation
This guide provides additional examples, some of which are Python code examples that use AWS SDK for Python (Boto) to make API calls...
Read more >
polly-proxy - npm
Does not support parallel tests (yet!) Proxies will be automatically cleaned up after a short time; The Polly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found