-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Sidekiq client middleware is same for clients & servers
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'ddtrace/contrib/support/spec_helper' | ||
require_relative 'support/helper' | ||
|
||
RSpec.describe Datadog::Contrib::Sidekiq::Patcher do | ||
before do | ||
Sidekiq.client_middleware.clear | ||
Sidekiq.server_middleware.clear | ||
|
||
allow(Sidekiq).to receive(:server?).and_return(server) | ||
# NB: This is needed because we want to patch multiple times. | ||
allow(described_class).to receive(:do_once).with(:patch).and_yield | ||
end | ||
|
||
# NB: This needs to be after the before block above so that the use :sidekiq | ||
# executes after the allows are setup. | ||
include_context 'Sidekiq testing' | ||
|
||
context 'for a client' do | ||
let(:server) { false } | ||
|
||
it 'correctly patches' do | ||
expect(Sidekiq.client_middleware.entries.map(&:klass)).to eq([Datadog::Contrib::Sidekiq::ClientTracer]) | ||
expect(Sidekiq.server_middleware.entries.map(&:klass)).to eq([]) | ||
end | ||
end | ||
|
||
context 'for a server' do | ||
let(:server) { true } | ||
|
||
it 'correctly patches' do | ||
expect(Sidekiq.client_middleware.entries.map(&:klass)).to eq([Datadog::Contrib::Sidekiq::ClientTracer]) | ||
expect(Sidekiq.server_middleware.entries.map(&:klass)).to eq([Datadog::Contrib::Sidekiq::ServerTracer]) | ||
end | ||
end | ||
end |