ActiveRecord 7.1 test failures

I am attempting to bring Occams CMS into Rails 7.1 compatibility (Rails 7.1 compatibility by avonderluft · Pull Request #14 · avonderluft/occams · GitHub). My test suite passes consistently on 6.1 and 7.0, but fails roughly 1 out of 4 times on 7.1 with things like:

  • Cannot expire connection, it is owned by a different thread
  • cannot start a transaction within a transaction
  • SQLite3::BusyException: database is locked

I’ve tried a lot of different workarounds, but to no avail. I tried running test suite in postgresql and mysql, but with much the same results. Any tips or hints would be very much appreciated!

Have you tried setting use_transactional_tests to false?

yes, thanks @pbstriker38. Still get lock errors:

SQLite3::BusyException: database is locked

I’m familiar with Postgres but wondering whether SQLite has a mechanism to log query text when a query is canceled (blocked) due to failing to acquire a lock? If so you might be able to identify the source query or query holding a lock.

Is it SQLite only where the failure happens?

no, I tried with MySQL as well.

This is curious, because it’s possible in PostgreSQL anyway. There are warnings but not errors.

@localhost:5432 # BEGIN;
BEGIN
@localhost:5432 # BEGIN;
WARNING:  there is already a transaction in progress
BEGIN
@localhost:5432 # COMMIT;
COMMIT
@localhost:5432 # COMMIT;
WARNING:  there is no transaction in progress
COMMIT

For Cannot expire connection I’d have to search the source code.

What version of PostgreSQL did you try? And I assume it’s a “stock” configuration with things like the transaction isolation level left in their default values?

psql (16.1) on macos running this minitest suite hangs and/or produces errors like:

WARNING:  there is already a transaction in progress
Emessage type 0x49 arrived from server while idle
message type 0x5a arrived from server while idle
.....................................................................................F.........................................................................................................................message type 0x49 arrived from server while idle
message type 0x5a arrived from server while idle
message type 0x49 arrived from server while idle

I’m facing the same issue. @avonderluft have you managed to figure this out yet? I’m trying to find which tests cause this to lock exactly. I am using minitest too.

@marelons1337 - no, sadly I have not. I post here if anything comes to light.

@avonderluft Im facing the same issue. I discovered that when I run the tests pointing to a single file the error does not occur. but if I run the tests pointing to an entire folder the error appears

Can you remove Spring and retry? Spring creates more headaches than any problem it solves.

1 Like

Yes @Bala_Paranj1 for some reason when i remove Spring that doesn’t happen again. I also tried with adding self.use_transactional_tests = false to the test helper and also worked.

It keeps the application running in the background and due to its persistent state can cause problems in tests.

1 Like

Hey, I have the same issue. Tests(RSpec) are running smoothly in 7.0.2 but trying any 7.1.* version is failing with transaction errors.

It would be really helpful if anyone can share any info on this topic. We are not using Spring. Thanks

@alejanderl

Try adding this config.active_job.queue_adapter = :test

in config/environments/test.rb

It works. Thanks !!!

I made a number of changes, including this. I’m not certain but I think this is what did the trick. Thanks.