mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
correct some test concurrency bugs
This commit is contained in:
parent
c9dcffe434
commit
cc088956bc
@ -8,7 +8,7 @@ require_dependency 'distributed_mutex'
|
|||||||
|
|
||||||
module Scheduler
|
module Scheduler
|
||||||
class Manager
|
class Manager
|
||||||
attr_accessor :random_ratio, :redis
|
attr_accessor :random_ratio, :redis, :enable_stats
|
||||||
|
|
||||||
class Runner
|
class Runner
|
||||||
def initialize(manager)
|
def initialize(manager)
|
||||||
@ -69,13 +69,15 @@ module Scheduler
|
|||||||
begin
|
begin
|
||||||
info.prev_result = "RUNNING"
|
info.prev_result = "RUNNING"
|
||||||
@mutex.synchronize { info.write! }
|
@mutex.synchronize { info.write! }
|
||||||
stat = SchedulerStat.create!(
|
if @manager.enable_stats
|
||||||
name: klass.to_s,
|
stat = SchedulerStat.create!(
|
||||||
hostname: hostname,
|
name: klass.to_s,
|
||||||
pid: Process.pid,
|
hostname: hostname,
|
||||||
started_at: Time.zone.now,
|
pid: Process.pid,
|
||||||
live_slots_start: GC.stat[:heap_live_slots]
|
started_at: Time.zone.now,
|
||||||
)
|
live_slots_start: GC.stat[:heap_live_slots]
|
||||||
|
)
|
||||||
|
end
|
||||||
klass.new.perform
|
klass.new.perform
|
||||||
rescue Jobs::HandledExceptionWrapper
|
rescue Jobs::HandledExceptionWrapper
|
||||||
# Discourse.handle_exception was already called, and we don't have any extra info to give
|
# Discourse.handle_exception was already called, and we don't have any extra info to give
|
||||||
@ -88,11 +90,13 @@ module Scheduler
|
|||||||
info.prev_duration = duration
|
info.prev_duration = duration
|
||||||
info.prev_result = failed ? "FAILED" : "OK"
|
info.prev_result = failed ? "FAILED" : "OK"
|
||||||
info.current_owner = nil
|
info.current_owner = nil
|
||||||
stat.update_columns(
|
if stat
|
||||||
duration_ms: duration,
|
stat.update_columns(
|
||||||
live_slots_finish: GC.stat[:heap_live_slots],
|
duration_ms: duration,
|
||||||
success: !failed
|
live_slots_finish: GC.stat[:heap_live_slots],
|
||||||
)
|
success: !failed
|
||||||
|
)
|
||||||
|
end
|
||||||
attempts(3) do
|
attempts(3) do
|
||||||
@mutex.synchronize { info.write! }
|
@mutex.synchronize { info.write! }
|
||||||
end
|
end
|
||||||
@ -151,6 +155,12 @@ module Scheduler
|
|||||||
|
|
||||||
@hostname = options && options[:hostname]
|
@hostname = options && options[:hostname]
|
||||||
@manager_id = SecureRandom.hex
|
@manager_id = SecureRandom.hex
|
||||||
|
|
||||||
|
if options && options.key?(:enable_stats)
|
||||||
|
@enable_stats = options[:enable_stats]
|
||||||
|
else
|
||||||
|
@enable_stats = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.current
|
def self.current
|
||||||
|
@ -54,7 +54,9 @@ describe Scheduler::Manager do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:manager) { Scheduler::Manager.new(DiscourseRedis.new) }
|
let(:manager) {
|
||||||
|
Scheduler::Manager.new(DiscourseRedis.new, enable_stats: false)
|
||||||
|
}
|
||||||
|
|
||||||
before do
|
before do
|
||||||
$redis.del manager.class.lock_key
|
$redis.del manager.class.lock_key
|
||||||
@ -79,7 +81,7 @@ describe Scheduler::Manager do
|
|||||||
|
|
||||||
hosts.map do |host|
|
hosts.map do |host|
|
||||||
|
|
||||||
manager = Scheduler::Manager.new(DiscourseRedis.new, hostname: host)
|
manager = Scheduler::Manager.new(DiscourseRedis.new, hostname: host, enable_stats: false)
|
||||||
manager.ensure_schedule!(Testing::PerHostJob)
|
manager.ensure_schedule!(Testing::PerHostJob)
|
||||||
|
|
||||||
info = manager.schedule_info(Testing::PerHostJob)
|
info = manager.schedule_info(Testing::PerHostJob)
|
||||||
@ -126,7 +128,7 @@ describe Scheduler::Manager do
|
|||||||
|
|
||||||
$redis.del manager.identity_key
|
$redis.del manager.identity_key
|
||||||
|
|
||||||
manager = Scheduler::Manager.new(DiscourseRedis.new)
|
manager = Scheduler::Manager.new(DiscourseRedis.new, enable_stats: false)
|
||||||
manager.reschedule_orphans!
|
manager.reschedule_orphans!
|
||||||
|
|
||||||
info = manager.schedule_info(Testing::SuperLongJob)
|
info = manager.schedule_info(Testing::SuperLongJob)
|
||||||
@ -174,7 +176,7 @@ describe Scheduler::Manager do
|
|||||||
|
|
||||||
(0..5).map do
|
(0..5).map do
|
||||||
Thread.new do
|
Thread.new do
|
||||||
manager = Scheduler::Manager.new(DiscourseRedis.new)
|
manager = Scheduler::Manager.new(DiscourseRedis.new, enable_stats: false)
|
||||||
manager.blocking_tick
|
manager.blocking_tick
|
||||||
manager.stop!
|
manager.stop!
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user