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)
|
def stop!(finish_work: false)
|
||||||
if finish_work
|
if finish_work
|
||||||
@finish = true
|
@finish = true
|
||||||
|
@queue.push({ finish: true }, force: true)
|
||||||
@thread&.join
|
@thread&.join
|
||||||
end
|
end
|
||||||
@thread.kill if @thread&.alive?
|
@thread.kill if @thread&.alive?
|
||||||
|
@ -108,7 +109,9 @@ module Scheduler
|
||||||
|
|
||||||
# using non_block to match Ruby #deq
|
# using non_block to match Ruby #deq
|
||||||
def do_work(non_block = false)
|
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)
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
db ||= RailsMultisite::ConnectionManagement::DEFAULT
|
db ||= RailsMultisite::ConnectionManagement::DEFAULT
|
||||||
|
|
|
@ -22,6 +22,12 @@ RSpec.describe Scheduler::Defer do
|
||||||
Discourse.reset_catch_job_exceptions!
|
Discourse.reset_catch_job_exceptions!
|
||||||
end
|
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
|
it "supports basic instrumentation" do
|
||||||
@defer.later("first") {}
|
@defer.later("first") {}
|
||||||
@defer.later("first") {}
|
@defer.later("first") {}
|
||||||
|
|
Loading…
Reference in New Issue