discourse/app
Alan Guo Xiang Tan 8a7b62b126
DEV: Fix threading error when running jobs immediately in system tests (#19811)
```
class Jobs::DummyDelayedJob < Jobs::Base
  def execute(args = {})
  end
end

RSpec.describe "Jobs.run_immediately!" do
  before { Jobs.run_immediately! }

  it "explodes" do
    current_user = Fabricate(:user)
    Jobs.enqueue_in(1.seconds, :dummy_delayed_job)
    sign_in(current_user)
  end
end
```

The test above will fail with the following error if `ActiveRecord::Base.connection_handler.clear_active_connections!` is called before the configured Capybara server checks out a connection from the connection pool.

```
     ActiveRecord::ActiveRecordError:
       Cannot expire connection, it is owned by a different thread: #<Thread:0x00007f437391df58@puma srv tp 001 /home/tgxworld/.asdf/installs/ruby/3.1.3/lib/ruby/gems/3.1.0/gems/puma-6.0.2/lib/puma/thread_pool.rb:106 sleep_forever>. Current thread: #<Thread:0x00007f437d6cfc60 run>.
```

We're not exactly sure if this is an ActiveRecord bug or not but we've
invested too much time into investigating this problem. Fundamentally,
we also no longer understand why `ActiveRecord::Base.connection_handler.clear_active_connections!` is being called in an ensure block
within `Jobs::Base#perform` which was added in
ceddb6e0da 10 years ago. This
commit moves the logic for running jobs immediately out of the
`Jobs::Base#perform` method into another `Jobs::Base#perform_immediately` method such that
`ActiveRecord::Base.connection_handler.clear_active_connections!` is not
called. This change will only impact the test environment.
2023-01-10 13:41:25 +08:00
..
assets UX: improve use of space for readability of admin email modal (#19797) 2023-01-09 14:24:58 +01:00
controllers DEV: Apply syntax_tree formatting to `app/*` 2023-01-09 14:14:59 +00:00
helpers DEV: Apply syntax_tree formatting to `app/*` 2023-01-09 14:14:59 +00:00
jobs DEV: Fix threading error when running jobs immediately in system tests (#19811) 2023-01-10 13:41:25 +08:00
mailers DEV: Apply syntax_tree formatting to `app/*` 2023-01-09 14:14:59 +00:00
models DEV: Apply syntax_tree formatting to `app/*` 2023-01-09 14:14:59 +00:00
serializers DEV: Do not include method definitions in serializer `attributes` 2023-01-09 14:15:00 +00:00
services DEV: Apply syntax_tree formatting to `app/*` 2023-01-09 14:14:59 +00:00
views UX: add btn-primary class on email confirm page (#19803) 2023-01-09 15:26:56 -05:00