Skip to content

Conversation

@faraquet
Copy link

@faraquet faraquet commented Oct 26, 2025

On the latest Rails, the tests are broken.

Failure:
DispatcherTest#test_polling_queries_are_logged [test/unit/dispatcher_test.rb:48]:
Expected /SELECT .* FROM .solid_queue_scheduled_executions. WHERE/ to match "".

bin/rails test test/unit/dispatcher_test.rb:39

Failure:
WorkerTest#test_polling_queries_are_logged [test/unit/worker_test.rb:114]:
Expected /SELECT .* FROM .solid_queue_ready_executions. WHERE .solid_queue_ready_executions...queue_name./ to match "".

bin/rails test test/unit/worker_test.rb:105

Reason

Rails migrated framework log subscribers to structured events via ActiveSupport::EventReporter, making SQL logs debug-only structured events. See PR: Make framework log subscribers consume structured events (https://github.com/rails/rails/pull/55900/files).

What broke

Tests that captured SQL via a StringIO logger and matched SELECT statements no longer saw logs unless EventReporter debug mode was enabled and the subscriber logger was pointed at the StringIO.

Solution

Added LoggingTestHelper with:

  • with_polling to toggle SolidQueue.silence_polling for deterministic polling logs.
  • with_active_record_logger to:
    • Always redirect ActiveRecord::Base.logger to the test StringIO.
    • If Rails uses structured events (≥ 8.1), enable ActiveSupport.event_reporter.debug_mode and redirect ActiveSupport::LogSubscriber.logger to the StringIO using one-line flip: old_as_ls_logger, ActiveSupport::LogSubscriber.logger = ActiveSupport::LogSubscriber.logger, logger, restoring afterward.
  • Pre-8.1 Rails: falls back to previous behavior (no EventReporter calls).

@faraquet faraquet force-pushed the aaa/tests branch 5 times, most recently from 65a5631 to 126584e Compare October 26, 2025 21:34
@faraquet faraquet changed the title Add PollingAndLoggingTestHelper and refactor tests Add LoggingTestHelper and refactor tests to use it Oct 26, 2025
@faraquet faraquet force-pushed the aaa/tests branch 3 times, most recently from 2752c9d to b6b56ad Compare October 26, 2025 22:15
@faraquet faraquet marked this pull request as ready for review October 26, 2025 22:23
@faraquet faraquet force-pushed the aaa/tests branch 2 times, most recently from 2509fe0 to e3777c2 Compare October 26, 2025 22:33
@faraquet faraquet changed the title Add LoggingTestHelper and refactor tests to use it Testing against Rails 8.1 Oct 26, 2025
@faraquet faraquet force-pushed the aaa/tests branch 2 times, most recently from 2012cfc to 81c9b49 Compare October 26, 2025 22:41
Introduced LoggingTestHelper to encapsulate logging-related test
utilities. Updated ActiveSupport::TestCase to include the new helper and
removed redundant logging methods from DispatcherTest and WorkerTest,
improving code organization and maintainability.
@p-schlickmann
Copy link
Contributor

p-schlickmann commented Oct 27, 2025

Great work @faraquet!

But I wonder if Rails is gonna fix this behaviour upstream? Since other people are also having issues?

Also, the failures are against rails_main, which is the unreleased version of 8.2, not 8.1.

But yes, I agree we should add 8.1 to the matrix since it was released past Wednesday. Maybe in a separate PR?

@faraquet faraquet changed the title Testing against Rails 8.1 Testing against rails_main Oct 27, 2025
@faraquet
Copy link
Author

Thank you so much @p-schlickmann

But yes, I agree we should add 8.1 to the matrix since it was released past Wednesday. Maybe in a separate PR?

Extracted into #668

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants