newrelic-ruby-agent icon indicating copy to clipboard operation
newrelic-ruby-agent copied to clipboard

CI: Add before_all_suites/after_all_suites functionality to multiverse

Open tannalynn opened this issue 2 years ago • 1 comments

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.

tannalynn avatar May 11 '22 18:05 tannalynn

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

hannahramadan avatar May 01 '23 20:05 hannahramadan

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:

  1. Use the minitest-hooks gem
  2. 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.

fallwith avatar Jun 21 '23 22:06 fallwith