Skip to content

Commit

Permalink
Log where schedulers are created to track down flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Apr 11, 2023
1 parent 10e9d9b commit 7e374f9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/good_job/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ def initialize(performer, max_threads: nil, max_cache: nil, warm_cache_on_initia

self.class.instances << self

@id = SecureRandom.uuid

source = ActiveSupport::BacktraceCleaner.new.clean(caller.lazy.reject { |line| line.include? File.expand_path(File.dirname(__FILE__)) }).first
puts "\nCreated GoodJob::Scheduler `#{@id}`"
puts "↳ #{source}"

@performer = performer

@max_cache = max_cache || 0
Expand All @@ -84,7 +90,7 @@ def initialize(performer, max_threads: nil, max_cache: nil, warm_cache_on_initia
@executor_options[:max_threads] = max_threads
@executor_options[:max_queue] = max_threads
end
@name = "GoodJob::Scheduler(queues=#{@performer.name} max_threads=#{@executor_options[:max_threads]})"
@name = "GoodJob::Scheduler(id=#{@id} queues=#{@performer.name} max_threads=#{@executor_options[:max_threads]})"
@executor_options[:name] = name

@cleanup_tracker = CleanupTracker.new(cleanup_interval_seconds: cleanup_interval_seconds, cleanup_interval_jobs: cleanup_interval_jobs)
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/good_job/capsule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
capsule = described_class.new
Array.new(100) { Thread.new { capsule.start } }.each(&:join)
capsule.shutdown
expect(GoodJob::Scheduler.instances.size).to eq 1
expect(GoodJob::Scheduler.instances.size).to eq(1), "Found more than 1 scheduler instance: #{GoodJob::Scheduler.instances.map(&:name).join(", ")}"
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/lib/good_job/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

describe 'name' do
it 'is human readable and contains configuration values' do
allow(SecureRandom).to receive(:uuid).and_return('1234')
scheduler = described_class.new(performer)
expect(scheduler.name).to eq('GoodJob::Scheduler(queues= max_threads=5)')
expect(scheduler.name).to eq("GoodJob::Scheduler(id=1234 queues= max_threads=5)")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/reset_good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
THREAD_ERRORS.clear
Thread.current.name = "RSpec: #{example.description}"
GoodJob.on_thread_error = lambda do |exception|
THREAD_ERRORS << [Thread.current.name, exception, exception.backtrace]
THREAD_ERRORS << [Thread.current.name, Thread.current.status, exception, exception.backtrace]
end

example.run
Expand Down

0 comments on commit 7e374f9

Please sign in to comment.