betamax icon indicating copy to clipboard operation
betamax copied to clipboard

Make cassettes thread-safe

Open sigmavirus24 opened this issue 9 years ago • 1 comments

I'm wondering if there's a need to test items using requests in thread-safe manner and how that would work with betamax. Currently the access to cassette files is not threadsafe and I'm wondering what would be necessary to ensure thread-safety.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9271963-make-cassettes-thread-safe?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F198445&utm_medium=issues&utm_source=github).

sigmavirus24 avatar Mar 06 '15 17:03 sigmavirus24

So, we'd probably have to use pylockfile to ensure we don't update the same cassette twice. That would probably give us 90% of what we need. Namely, this would be great for the case where we are testing an application that's sharing a session between threads. Even though this isn't a recommendation requests makes, Betamax should still attempt to support it.

Further, I think the dependency on pylockfile should be optional that could be installed from an extra for betamax, e.g., pip install betamax[threadsafe].

The code to integrate this with the current Cassette class should be minimal.

sigmavirus24 avatar Jul 16 '15 19:07 sigmavirus24