Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@cgunther
Copy link
Contributor

@cgunther cgunther commented Jul 31, 2019

Background

When VCR is first used in the main (test) thread, it initializes a context, holding the status of whether VCR is turned off. When another thread is started (ie. app server), VCR initializes a context there by duplicating the main thread's context and linking to the main thread's context.

If you turned off VCR in the main thread after it's context was duplicated to an additional thread, the additional thread wouldn't see the new turned off status (since it was only on the linked context), so it'd fail thinking VCR was still turned on but no cassette was inserted when a request was made.

Solution

Now we check both the current thread's context, and the linked (main) thread's context to see if VCR is turned off, to ensure an app server thread can see when VCR is turned off on the main thread.

Details

This was most noticeable in Capybara tests with a JS driver where the app server thread was started once upon the first spec needing it, thus duplicating the main thread's context then, but if later specs turned off VCR, the app server thread never had it's context updated to reflect that, nor did it check the main thread's context to see if VCR was turned off there.

When VCR is first used in the main (test) thread, it initializes a
context, holding the status of whether VCR is turned off. When another
thread is started (ie. app server), VCR initializes a context there by
duplicating the main thread's context and linking to the main thread's
context.

If you turned off VCR in the main thread after it's context was
duplicated to an additional thread, the additional thread wouldn't see
the new turned off status (since it was only on the linked context), so
it'd fail thinking VCR was still turned on but no cassette was inserted
when a request was made.

Now we check both the current thread's context, and the linked (main)
thread's context to see if VCR is turned off, to ensure an app server
thread can see when VCR is turned off on the main thread.

This was most noticeable in Capybara tests with a JS driver where the
app server thread was started once upon the first spec needing it, thus
duplicating the main thread's context then, but if later specs turned
off VCR, the app server thread never had it's context updated to reflect
that, nor did it check the main thread's context to see if VCR was
turned off there.
@yiyuanc
Copy link

yiyuanc commented Aug 15, 2019

this looks good to me!

@olleolleolle
Copy link
Member

(I added formatting markup to the Description of this PR, to ease navigation and skim-reading.)

@krainboltgreene krainboltgreene merged commit 35c5186 into vcr:master Dec 24, 2019
@cgunther
Copy link
Contributor Author

Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants