testdouble / cypress-rails

Helps you write Cypress tests of your Rails app
Other
321 stars 48 forks source link

`cypress-rails` will not start on rails 6.1.4 #88

Closed grxy closed 3 years ago

grxy commented 3 years ago

Here are the logs I get when running bin/rails cypress:open on my computer and bin/rails cypress:run in CI:

bin/rails cypress:open

cypress-rails configuration:
============================
 CYPRESS_RAILS_DIR....................."..."
 CYPRESS_RAILS_HOST...................."..."
 CYPRESS_RAILS_PORT...................."9400"
 CYPRESS_RAILS_BASE_PATH..............."/"
 CYPRESS_RAILS_TRANSACTIONAL_SERVER....true
 CYPRESS_RAILS_CYPRESS_OPTS............""

Traceback (most recent call last):
    11: from /path/to/gems/cypress-rails-0.5.0/exe/cypress-rails:13:in `<main>'
    10: from /path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/open.rb:11:in `call'
     9: from /path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/launches_cypress.rb:20:in `call'
     8: from /path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/manages_transactions.rb:10:in `begin_transaction'
     7: from /path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/manages_transactions.rb:59:in `gather_connections'
     6: from path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/manages_transactions.rb:71:in `setup_shared_connection_pool'
     5: from /path/to/gems/cypress-rails-0.5.0/lib/cypress-rails/manages_transactions.rb:71:in `call'
     4: from /path/to/gems/activerecord-6.1.4/lib/active_record/test_fixtures.rb:199:in `setup_shared_connection_pool'
     3: from /path/to/gems/activerecord-6.1.4/lib/active_record/test_fixtures.rb:199:in `each'
     2: from /path/to/gems/activerecord-6.1.4/lib/active_record/test_fixtures.rb:201:in `block in setup_shared_connection_pool'
     1: from /path/to/gems/activerecord-6.1.4/lib/active_record/test_fixtures.rb:201:in `each'
/path/to/gems/activerecord-6.1.4/lib/active_record/test_fixtures.rb:207:in `block (2 levels) in setup_shared_connection_pool': undefined method `[]' for nil:NilClass (NoMethodError)

Seems like there were some recent changes to the way setup_shared_connection_pool works that cause cypress-rails to be totally unusable with this particular version of rails.

CC: @dflynn15

gilesbowkett commented 3 years ago

this happens because of line 71 in manages_transactions.rb. you can fake it out by modifying ActiveRecord's activerecord/lib/active_record/test_fixtures.rb like this:

image

at the risk of stating the obvious, I do not actually think you should do this in production! but it's a good way to validate my diagnosis.

the ManagesTransactions class has a method called gather_connections. this calls a method called setup_shared_connection_pool, which leads to the code in test_fixtures.rb in ActiveRecord exploding.

gilesbowkett commented 3 years ago

commenting out line 71 in manages_transactions.rb also works.

line 71

searls commented 3 years ago

Hey Giles, sorry I hadn't had a chance to look at this previously. I'm unsure if the right option is to add a new option or just do a little more checking about either version or connection pool configuration before making this call. I'll try to look at it this week.

gilesbowkett commented 3 years ago

@searls all good, no rush

searls commented 3 years ago

Hey @gilesbowkett & @grxy -- I am somewhat confident that this particular error was just fixed in 0.5.1, but I am not confident at all that the underlying intention was ever working correctly. As a result, I'd love if you could try this out and see if you encounter any issues

gilesbowkett commented 3 years ago

Circle is down right now but it works fine on my machine.

I actually thought I didn't have a connection pool in the app where this came up, but after checking my config/database.yml, it looks like I do. so there's a bit of a 🤷🏻‍♂️ factor, but it's working.

searls commented 3 years ago

@gilesbowkett yeah, if you read the AR code, the only way to trigger the error you and @grxy experienced was if you did have a pool in use.

Also I just switched from Circle to GitHub Actions today while debugging this

gilesbowkett commented 3 years ago

yeah, if you read the AR code, the only way to trigger the error you and @grxy experienced was if you did have a pool in use.

image

who reads code though

searls commented 3 years ago

heh, we're on the same page

I learned a long time ago nobody reads code, much less verifies it. The last thing people need is more inhibition / shame.