newrelic-ruby-agent
newrelic-ruby-agent copied to clipboard
CI: Add before_all_suites/after_all_suites functionality to multiverse
Currently, when running the active_record_pg
mutliverse suite, in the before_suite.rb, we are dropping and creating the database before each environment run. This is there to prevent the database from growing too large since the tests don't all clean up after themselves. In the CI this is fine because the CI runs multiverse serialized rather than parallel. However, when running this suite locally this can cause this error to occur when attempting to drop the database while another process is running the suite as well.
PG::ObjectInUse: ERROR: database "multiverse_activerecord_6_1_6_2_7_4_ruby" is being accessed by other users
DETAIL: There is 1 other session using the database.
Couldn't drop database 'multiverse_activerecord_6_1_6_2_7_4_ruby'
Also, it looks like this error doesn't seem to happen when running on ruby version 2.5, but does happen on 2.7. It doesn't look like multiverse has the ability to do a before_all_suites/after_all_suites which is where this type of behavior should be instead to avoid parallelism issues.
https://issues.newrelic.com/browse/NEWRELIC-3458
Changed the active_record_pg test suite to always run in serial: https://github.com/newrelic/newrelic-ruby-agent/pull/1980
Leaving this ticket open to address the a new todo:
TODO: Devise a way for an individual suite to express that it doesn't support parallel
If we decide in future that we really want "before all" / "after all" or "setup once" / "teardown once" functionality, there's this article from Ruslan that offers 2 good choices:
- Use the minitest-hooks gem
- Simply put your "before all" code inline (outside of any method definition) at the top of the class before any test definitions and then follow up with an inline
Minitest.after_run {}
block that contains all of your "after all" code.