Skip to content

Conversation

@p-schlickmann
Copy link
Contributor

@p-schlickmann p-schlickmann commented Nov 3, 2025

Issue: #602
Flake reference: https://github.com/rails/solid_queue/blob/main/test/unit/dispatcher_test.rb
Failed run: https://github.com/rails/solid_queue/actions/runs/18917303921/job/54003968729

Summary

  1. polling queries are logged — Rewind StringIO and increase sleep
  2. polling queries can be silenced — Rewind StringIO and increase sleep
  3. silencing polling queries when there's no Active Record logger — Increase sleep
  4. run more than one instance of the dispatcher — Increase AddToBufferJob wait and increase sleep
  5. sleeps 0.seconds between polls if there are ready to dispatch jobs — Increase AddToBufferJob wait and increase sleep

While the CI logs helped diagnose flakes in tests 1 and 2, the following command was useful to reproduce others locally:

export TARGET_DB=sqlite
export BUNDLE_GEMFILE=./gemfiles/rails_7_1.gemfile # or whatever
export RAILS_ENV=test
# Run 4000 tests in parallel using 4 CPUs (you must install `parallel` CLI)
seq 1 4000 | parallel -j4 --halt now,fail=1 'TEST_ENV_NUMBER={%} bin/rails test test/unit/dispatcher_test.rb'

You might also need to add TEST_ENV_NUMBER to database.yml:

test:
  primary:
    <<: *default
    database: <%= database_name_from("test" + ENV["TEST_ENV_NUMBER"]) %>
  shard_one:
    <<: *default
    database: <%= database_name_from("test_shard_one" + ENV["TEST_ENV_NUMBER"]) %>
    migrations_paths: db/migrate_shards
  shard_two:
    <<: *default
    database: <%= database_name_from("test_shard_two" + ENV["TEST_ENV_NUMBER"]) %>
    migrations_paths: db/migrate_shards
  queue:
    <<: *default
    database: <%= database_name_from("test_queue" + ENV["TEST_ENV_NUMBER"]) %>
    migrations_paths: db/queue_migrate

And also modify the log path for environments/test.rb:

Rails.application.configure do
    # ...
    config.paths["log"] = "log/test#{ENV['TEST_ENV_NUMBER']}.log"
end

@p-schlickmann p-schlickmann force-pushed the flaky-dispatcher-tests branch from 636b4f3 to e7fcd57 Compare November 3, 2025 20:01
@rosa
Copy link
Member

rosa commented Nov 4, 2025

Awesome @p-schlickmann! 🙇🏻‍♀️

@rosa rosa merged commit 2a90213 into rails:main Nov 4, 2025
52 checks passed
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