Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop database cleaner and use rails system specs #898

Open
timdiggins opened this issue Jul 15, 2021 · 10 comments
Open

Drop database cleaner and use rails system specs #898

timdiggins opened this issue Jul 15, 2021 · 10 comments

Comments

@timdiggins
Copy link
Collaborator

Split out from #894.

Now we are freed of pre rails 5.2 (#894), we no longer need database cleaner as we can use rails system specs.

This has multiple benefits (reliability, test flexibility, possibly speed).

@timdiggins timdiggins changed the title Drop database cleaner and use rails system specs (or as separate PR) Drop database cleaner and use rails system specs Jul 15, 2021
@timdiggins
Copy link
Collaborator Author

FYI Have found an issue when working on this: mysql migration spec support.

@timdiggins
Copy link
Collaborator Author

We have switched to system specs: #910

However dropping database cleaner altogether is tricky: migration specs rely on it, and there is a usage of it in user_searches_for_topics_spec.rb which is hard to replace.

Additionally just trying to replace the remaining usages of DatabaseCleaner with use_transactional_fixtures has some occasional random failures. https://app.travis-ci.com/github/thredded/thredded/builds/246469536

So parking this for now.

@dgm
Copy link

dgm commented Jan 13, 2023

I'm trying to drop database cleaner in a project that uses thredded, in favor of rails transactional system tests. Tests that create thredded objects have a tendancy to crash with malloc errors, deadlocks, or double free problems. What's different about thredded from the all the other rails gems we've used? Any tips on doing system tests with thredded objects in our own project?

@timdiggins
Copy link
Collaborator Author

The only slightly unusual thing with Thredded is that the app uses threads to render some things in parallel (this is really a way of dealing with onebox). So maybe if your app has some problems with threading that might

I've run Thredded-related tests in a project which uses transactional system tests successfully, including without database-cleaner

@dgm
Copy link

dgm commented Jan 16, 2023

We don't really use threads, in production anyway, but apparently rspec is, and when I remove database cleaner and turn on transactional tests, they hang only when using thredded. Is there a way to disable threads ?

@dgm
Copy link

dgm commented Jan 17, 2023

Upon further reflection, this kind of has me worried - I run production in a per-process environment, not expecting threads. Is this a possible time bomb under heavy load?

@glebm
Copy link
Collaborator

glebm commented Jan 17, 2023

You can disable threaded rendering like this:

# config/initializers/thredded.rb
Thredded::CollectionToStringsWithCacheRenderer.render_threads = 1

The default is 50.

Threads not working correctly likely indicates other issues in your application.

@dgm
Copy link

dgm commented Jan 17, 2023

I'm sorry to hijack this thread, it's the only thing remotely close to the problem I'm seeing. This didn't affect anything, but I got an error this time that makes me wonder about the interaction of rspec before actions, mysql, active job and thredded. The other interesting thing here is that we don't use active job, we use delayed_job gem so I don't think we have any configuration set for active job. It appears like active job is continuing to act on things after rspec has initiated the rollback.

CACHE Thredded::Messageboard Load (0.0ms) SELECT `thredded_messageboards`.* FROM `thredded_messageboards` INNER JOIN `thredded_messageboard_commentables` ON `thredded_messageboards`.`id` = `thredded_messageboard_commentables`.`thredded_messageboard_id` WHERE `thredded_messageboard_commentables`.`commentable_id` = 1292 AND `thredded_messageboard_commentables`.`commentable_type` = 'RootCause' ORDER BY `thredded_messageboards`.`id` ASC LIMIT 1 CACHE Thredded::Messageboard Load (0.0ms) SELECT `thredded_messageboards`.* FROM `thredded_messageboards` INNER JOIN `thredded_messageboard_commentables` ON `thredded_messageboards`.`id` = `thredded_messageboard_commentables`.`thredded_messageboard_id` WHERE `thredded_messageboard_commentables`.`commentable_id` = 407 AND `thredded_messageboard_commentables`.`commentable_type` = 'FundingSource' ORDER BY `thredded_messageboards`.`id` ASC LIMIT 1 CACHE Thredded::Messageboard Load (0.0ms) SELECT `thredded_messageboards`.* FROM `thredded_messageboards` INNER JOIN `thredded_messageboard_commentables` ON `thredded_messageboards`.`id` = `thredded_messageboard_commentables`.`thredded_messageboard_id` WHERE `thredded_messageboard_commentables`.`commentable_id` = 721 AND `thredded_messageboard_commentables`.`commentable_type` = 'Monitor::InstrumentResponse' ORDER BY `thredded_messageboards`.`id` ASC LIMIT 1 TRANSACTION (10.3ms) ROLLBACK [ActiveJob] [Thredded::AutoFollowAndNotifyJob] [eaaee121-44be-4c62-b2b1-eb5ae6b7df12] Thredded::Post Load (2.2ms) SELECT `thredded_posts`.* FROM `thredded_posts` WHERE `thredded_posts`.`id` = 120 LIMIT 1 [ActiveJob] [Thredded::AutoFollowAndNotifyJob] [eaaee121-44be-4c62-b2b1-eb5ae6b7df12] Error performing Thredded::AutoFollowAndNotifyJob (Job ID: eaaee121-44be-4c62-b2b1-eb5ae6b7df12) from Async(default) in 1050.95ms: ActiveRecord::StatementInvalid (Mysql2::Error::ConnectionError: Lost connection to MySQL server during query): /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `_query' /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/mysql2-0.5.4/lib/mysql2/client.rb:148:in `block in query' /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `handle_interrupt' /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/mysql2-0.5.4/lib/mysql2/client.rb:147:in `query' /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/activerecord-6.1.7/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute' /Users/dmorton/.rvm/gems/ruby-2.7.7/gems/activesupport-6.1.7/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'

@dgm
Copy link

dgm commented Jan 17, 2023

Yes, that led me to look at your spec helper, and I added this to my spec helper:

ActiveJob::Base.queue_adapter = :inline

And now the tests run to completion without deadlocks or other problems.

@timdiggins
Copy link
Collaborator Author

(Yes, this is going quite off topic now, but continuing the discussion here anyway) It sounds like your ActiveJobs / DelayedJobs were running in your tests but in the background. This is not one of the default out of the box configs AFAIK for test setup - you either run them inline, or to queue them but either clear them or run them manually when you need to.

Anyway this doesn't seem thredded-specific but glad it's solved for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants