mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 16:35:43 +08:00
DEV: fix hanging spec (#29974)
This commit is contained in:
parent
2d945e2373
commit
07813ba83c
|
@ -76,6 +76,7 @@ module Scheduler
|
|||
def stop!(finish_work: false)
|
||||
if finish_work
|
||||
@finish = true
|
||||
@queue.push({ finish: true }, force: true)
|
||||
@thread&.join
|
||||
end
|
||||
@thread.kill if @thread&.alive?
|
||||
|
@ -108,7 +109,9 @@ module Scheduler
|
|||
|
||||
# using non_block to match Ruby #deq
|
||||
def do_work(non_block = false)
|
||||
db, job, desc = @queue.shift(block: !non_block).values_at(:db, :job, :desc)
|
||||
db, job, desc, finish = @queue.shift(block: !non_block).values_at(:db, :job, :desc, :finish)
|
||||
|
||||
return if finish
|
||||
|
||||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
db ||= RailsMultisite::ConnectionManagement::DEFAULT
|
||||
|
|
|
@ -22,6 +22,12 @@ RSpec.describe Scheduler::Defer do
|
|||
Discourse.reset_catch_job_exceptions!
|
||||
end
|
||||
|
||||
it "can finish work properly without crashing" do
|
||||
@defer.later {}
|
||||
sleep 0.005
|
||||
@defer.stop!(finish_work: true)
|
||||
end
|
||||
|
||||
it "supports basic instrumentation" do
|
||||
@defer.later("first") {}
|
||||
@defer.later("first") {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user