sessions_jobs.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.configure do |config|
  3. config.before(type: :system) do |example|
  4. sessions_jobs_required = example.metadata.fetch(:sessions_jobs, false)
  5. next if !sessions_jobs_required
  6. allow_any_instance_of(Sessions::Backend::Base).to receive(:to_run?).and_return(true)
  7. end
  8. config.around(:each, type: :system) do |example|
  9. sessions_jobs_required = example.metadata.fetch(:sessions_jobs, false)
  10. if sessions_jobs_required
  11. sessions_jobs_thread = Thread.new do
  12. # Try to work around a problem with ActiveRecord::StatementInvalid: Mysql2::Error:
  13. # This connection is in use by: #<Thread:0x000000000e940e18 /builds/zammad/zammad/lib/sessions.rb:533 dead>
  14. ActiveRecord::Base.connection_pool.release_connection
  15. BackgroundServices::Service::ProcessSessionsJobs
  16. .new(manager: nil)
  17. .launch
  18. end
  19. end
  20. example.run
  21. next if !sessions_jobs_required
  22. sessions_jobs_thread.exit
  23. sessions_jobs_thread.join
  24. end
  25. end