twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

Intermittent error: The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported #50

Closed mateusg closed 4 years ago

mateusg commented 4 years ago

About 6 months ago I replaced capybara-webkit with apparition in an app I'm working on and started seeing this error coming up intermittently in the CI and also locally: The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported. According to RSpec's docs, it happens when a stub is created outside of the example context, but I'm not doing that.

The backtrace:

Randomized with seed 9970
..............*......#<Thread:0x000056402ed09688@/home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:221 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
    13: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:222:in `block in start_threads'
    12: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:161:in `cleanup_async_responses'
    11: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:161:in `loop'
    10: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:162:in `block in cleanup_async_responses'
     9: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:162:in `synchronize'
     8: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:164:in `block (2 levels) in cleanup_async_responses'
     7: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:164:in `each'
     6: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/apparition-0.5.0/lib/capybara/apparition/driver/chrome_client.rb:165:in `block (3 levels) in cleanup_async_responses'
     5: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/method_double.rb:64:in `block (2 levels) in define_proxy_method'
     4: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/verifying_proxy.rb:161:in `proxy_method_invoked'
     3: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/method_double.rb:77:in `proxy_method_invoked'
     2: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/proxy.rb:342:in `message_received'
     1: from /home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/space.rb:27:in `any_instance_recorders_from_ancestry_of'
/home/circleci/repo/vendor/bundle/ruby/2.6.0/gems/rspec-mocks-3.9.1/lib/rspec/mocks/space.rb:51:in `raise_lifecycle_message': The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported. (RSpec::Mocks::OutsideOfExampleError)
F.

If I rerun the same specs with the same seed it might pass or fail. The error doesn't always come from the same test, it can fail randomly on any test. When it causes one failure, it affects also other tests. Apparently database_cleaner ends up committing changes and not clearing the database on such failure.

I've tried updating RSpec to version 3.9, which fixes a thread-safety issue, and apparition to version 0.5.0, but the problem seems to persist. Any clue on what could be causing this? It seems like some kind of thread safety issue.

My app is using:

twalpole commented 4 years ago

It sounds like you have a timing issue, possibly caused by after test cleanup block order. I am curious why your stacktrace looks like you're mocking part of apparition though.

twalpole commented 4 years ago

Closing due to lack of response, way to reproducce