From 34881884b996f235148c30594c363beccaa0adeb Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Wed, 30 Jul 2025 16:12:29 +0100 Subject: [PATCH] Restore async test I've made sure the async session is available during the test, which fixes Rails 8 However... the test is a little flakey on Rails >= 7.1 && < 8.0.2, due to a thread-safe bug in Rails. I've skipped the flakey part of the test in those versions --- test/active_record_test.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/active_record_test.rb b/test/active_record_test.rb index 89d6601..c3f194d 100644 --- a/test/active_record_test.rb +++ b/test/active_record_test.rb @@ -187,11 +187,19 @@ class ActiveRecordTest < Minitest::Test } ) end + end - it "marks async queries with async: true" do + describe "async queries" do + before do skip "Not applicable to older rails" if Rails.version.to_f < 7.1 - skip "TODO: Fails on Rails 8 because of a missing session." if Rails.version.to_i >= 8 + ActiveRecord::Base.asynchronous_queries_tracker.start_session + end + after do + ActiveRecord::Base.asynchronous_queries_tracker.finalize_session + end + + it "marks async queries with async: true" do expected_sql = 'SELECT COUNT(*) FROM "samples"' messages = semantic_logger_events do @@ -209,6 +217,10 @@ class ActiveRecordTest < Minitest::Test payload_includes: {sql: expected_sql} ) end + + # On Rails prior to 8.0.2, these assertions will mostly pass, but not always. + # https://github.com/rails/rails/pull/54344 + skip "Older Rails has flakey async instrumentation" if Rails.version < Gem::Version.new("8.0.2") refute messages[0].payload.key?(:async) assert_equal true, messages[1].payload[:async] end