testdouble / test_data

A fast & reliable system for managing your Rails application's test data
MIT License
99 stars 7 forks source link

Script/test: 51 on Reinitialize, error PG::ObjectInUse: ERROR: database "example_test_data" is being accessed by other users #16

Open infews opened 9 months ago

infews commented 9 months ago

Yes, I've allowed myself to get distracted by Rails 7.1 and sqlite support.

I'm getting small test failures due to 7.1 and have been fixing them in small commits. Now have gotten to [script/test: 51] and am failing here:

[script/test:51] $ bin/rake test_data:reinitialize
** Invoke test_data:reinitialize (first_time)
** Invoke test_data:verify_config (first_time)
** Execute test_data:verify_config
** Invoke environment (first_time)
** Execute environment
** Execute test_data:reinitialize
[test_data:warn] Your local test_data database 'example_test_data' is associated
with a SQL dump that was NEWER than the current dumps located in
'test/support/test_data':

  SQL Dump: 2024-02-22 16:38:47 -0800
  Database: 2024-02-22 16:38:54 -0800

If you're not intentionally resetting your local test_data database to an earlier
version, you may want to take a closer look before taking any destructive actions.

** Invoke test_data:drop_database (first_time)
** Invoke environment 
** Execute test_data:drop_database
PG::ObjectInUse: ERROR:  database "example_test_data" is being accessed by other users
DETAIL:  There is 1 other session using the database.
Couldn't drop database 'example_test_data'
rake aborted!
ActiveRecord::StatementInvalid: PG::ObjectInUse: ERROR:  database "example_test_data" is being accessed by other users (ActiveRecord::StatementInvalid)
DETAIL:  There is 1 other session using the database.

It looks like folks running into similar problems on drop_database and do some PG/kill foolery. Should I do this? Or is there some other spot where we should fix this?

infews commented 9 months ago

For example, we could monkey patch (sorry) something like this?

http://simon.rentzke.com/force-rails-to-db-drop-postgres-db-when-there-are-other-session-using-the-database/

infews commented 9 months ago

Ugh. I've tried flushing/closing connections at a bunch of places and can't get past this problem.

I've moved to Postgres v16, and that only seems to have made things worse as script/test is now crashing. :shakes_fist: