Skip to content

Commit 65b4e95

Browse files
committed
Test
Co-authored-by: Johannes Haass <johannes.haass@sap.com>
1 parent c1bb3ed commit 65b4e95

4 files changed

Lines changed: 10 additions & 1 deletion

File tree

app/jobs/generic_enqueuer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Jobs
55
class GenericEnqueuer < Enqueuer
66
def self.shared(priority: nil)
77
stored_instance = Thread.current[:generic_enqueuer]
8+
puts "[#{Process.pid} | #{Thread.current.object_id}] Shared enqueuer accessed: #{stored_instance} | Priority: #{priority}"
89
return stored_instance if stored_instance && priority.nil?
910

1011
new_instance = new(queue: Jobs::Queues.generic, priority: priority)
@@ -13,6 +14,7 @@ def self.shared(priority: nil)
1314
end
1415

1516
def self.reset!
17+
puts "Resetting GenericEnqueuer instance #{Thread.current[:generic_enqueuer]} in process: #{Process.pid} | Thread: #{Thread.current.object_id}"
1618
Thread.current[:generic_enqueuer] = nil
1719
end
1820
end

app/jobs/reoccurring_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def expire!
7878
def enqueue_next_job(pollable_job)
7979
run_at = Delayed::Job.db_time_now + next_execution_in
8080
@retry_number += 1
81+
puts "Enqueuing next job for #{self.class} with guid: #{pollable_job.guid} at #{run_at}"
82+
puts "Using generic enqueuer: #{Thread.current[:generic_enqueuer]} in process: #{Process.pid} | Thread: #{Thread.current.object_id}"
8183
Jobs::GenericEnqueuer.shared.enqueue_pollable(self, existing_guid: pollable_job.guid, run_at: run_at, preserve_priority: true)
8284
end
8385
end

spec/unit/jobs/generic_enqueuer_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def perform
2121

2222
before do
2323
# Reset singleton instance to ensure clean tests
24-
Thread.current[:generic_enqueuer] = nil
24+
puts 'Resetting GenericEnqueuer instance in before'
25+
GenericEnqueuer.reset!
2526
end
2627

2728
describe '.shared' do

spec/unit/jobs/reoccurring_job_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ def perform
7373
it 'keeps the delayed job\'s priority when re-enqueuing' do
7474
TestConfig.config[:jobs][:priorities] = { 'fake-job': 20 }
7575

76+
Jobs::GenericEnqueuer.reset! # Ensure no previous state interferes
77+
7678
pollable_job = Jobs::Enqueuer.new({ queue: Jobs::Queues.generic, priority: 22 }).enqueue_pollable(FakeJob.new)
79+
puts("All jobs before executing: #{Delayed::Job.all}")
7780
expect(Delayed::Job.where(guid: PollableJobModel.first.delayed_job_guid).first[:priority]).to eq(42)
7881

7982
execute_all_jobs(expected_successes: 1, expected_failures: 0, jobs_to_execute: 1)
83+
puts("All jobs after executing: #{Delayed::Job.all}")
8084

8185
expect(Delayed::Job.where(guid: PollableJobModel.first.delayed_job_guid).first[:priority]).to eq(42)
8286
expect(PollableJobModel.first.delayed_job_guid).not_to eq(pollable_job.delayed_job_guid)

0 commit comments

Comments
 (0)