Skip to content

Commit

Permalink
Use ActiveSupport::Testing::TimeHelpers to fix a flaky test that chec…
Browse files Browse the repository at this point in the history
…ks the message deduplication id
  • Loading branch information
hoffi committed Oct 25, 2023
1 parent fd8cf10 commit 82c3e6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gemspec

group :test do
gem 'activejob'
gem 'activesupport'
gem 'aws-sdk-core', '~> 3'
gem 'aws-sdk-sqs'
gem 'codeclimate-test-reporter', require: nil
Expand Down
17 changes: 11 additions & 6 deletions spec/shared_examples_for_active_job.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
require 'active_job'
require 'shoryuken/extensions/active_job_extensions'
require 'active_support/testing/time_helpers'

# Stand-in for a job class specified by the user
class TestJob < ActiveJob::Base; end

# rubocop:disable Metrics/BlockLength
RSpec.shared_examples 'active_job_adapters' do
include ActiveSupport::Testing::TimeHelpers

let(:job_sqs_send_message_parameters) { {} }
let(:job) do
job = TestJob.new
Expand Down Expand Up @@ -43,14 +46,16 @@ class TestJob < ActiveJob::Base; end
let(:fifo) { true }

it 'does not include job_id in the deduplication_id' do
expect(queue).to receive(:send_message) do |hash|
message_deduplication_id = Digest::SHA256.hexdigest(JSON.dump(job.serialize.except('job_id')))
freeze_time do
expect(queue).to receive(:send_message) do |hash|
message_deduplication_id = Digest::SHA256.hexdigest(JSON.dump(job.serialize.except('job_id')))

expect(hash[:message_deduplication_id]).to eq(message_deduplication_id)
end
expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)
expect(hash[:message_deduplication_id]).to eq(message_deduplication_id)
end
expect(Shoryuken).to receive(:register_worker).with(job.queue_name, described_class::JobWrapper)

subject.enqueue(job)
subject.enqueue(job)
end
end

context 'with message_deduplication_id' do
Expand Down

0 comments on commit 82c3e6a

Please sign in to comment.