-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ConcurrentSpan tests, add missing test coverage
- Loading branch information
1 parent
93138cf
commit 89ef625
Showing
8 changed files
with
186 additions
and
3 deletions.
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
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,118 @@ | ||
THREADS_COUNT = 10 | ||
REPEAT_COUNT = 20 | ||
|
||
RSpec.describe Datadog::CI::ConcurrentSpan do | ||
describe "#finish" do | ||
it "calls SpanOperation#stop once" do | ||
REPEAT_COUNT.times do | ||
tracer_span = Datadog::Tracing::SpanOperation.new("operation") | ||
ci_span = described_class.new(tracer_span) | ||
|
||
expect(tracer_span).to receive(:stop).once | ||
|
||
(1..THREADS_COUNT).map do | ||
Thread.new do | ||
ci_span.finish | ||
end | ||
end.map(&:join) | ||
end | ||
end | ||
end | ||
|
||
# the following tests make sure that ConcurrentSpan works exactly like Span | ||
let(:tracer_span) { instance_double(Datadog::Tracing::SpanOperation, name: "span_name", type: "test") } | ||
subject(:span) { described_class.new(tracer_span) } | ||
|
||
describe "#passed!" do | ||
it "sets the status to PASS" do | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "pass") | ||
|
||
span.passed! | ||
end | ||
end | ||
|
||
describe "#failed!" do | ||
context "when exception is nil" do | ||
it "sets the status to FAIL" do | ||
expect(tracer_span).to receive(:status=).with(1) | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "fail") | ||
|
||
span.failed! | ||
end | ||
end | ||
|
||
context "when exception is provided" do | ||
it "sets the status to FAIL" do | ||
expect(tracer_span).to receive(:status=).with(1) | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "fail") | ||
expect(tracer_span).to receive(:set_error).with("error") | ||
|
||
span.failed!(exception: "error") | ||
end | ||
end | ||
end | ||
|
||
describe "#skipped!" do | ||
context "when exception is nil" do | ||
it "sets the status to SKIP" do | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "skip") | ||
expect(tracer_span).not_to receive(:set_error) | ||
|
||
span.skipped! | ||
end | ||
end | ||
|
||
context "when exception is provided" do | ||
it "sets the status to SKIP and sets error" do | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "skip") | ||
expect(tracer_span).to receive(:set_error).with("error") | ||
|
||
span.skipped!(exception: "error") | ||
end | ||
end | ||
|
||
context "when reason is nil" do | ||
it "doesn't set the skip reason tag" do | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "skip") | ||
expect(tracer_span).not_to receive(:set_tag).with("test.skip_reason", "reason") | ||
|
||
span | ||
|
||
span.skipped! | ||
end | ||
end | ||
|
||
context "when reason is provided" do | ||
it "sets the skip reason tag" do | ||
expect(tracer_span).to receive(:set_tag).with("test.status", "skip") | ||
expect(tracer_span).to receive(:set_tag).with("test.skip_reason", "reason") | ||
|
||
span.skipped!(reason: "reason") | ||
end | ||
end | ||
end | ||
|
||
describe "#set_tag" do | ||
it "sets the tag" do | ||
expect(tracer_span).to receive(:set_tag).with("foo", "bar") | ||
|
||
span.set_tag("foo", "bar") | ||
end | ||
end | ||
|
||
describe "#set_tags" do | ||
it "sets the tags" do | ||
expect(tracer_span).to receive(:set_tags).with({"foo" => "bar", "baz" => "qux"}) | ||
|
||
span.set_tags("foo" => "bar", "baz" => "qux") | ||
end | ||
end | ||
|
||
describe "#set_metric" do | ||
it "sets the metric" do | ||
expect(tracer_span).to receive(:set_metric).with("foo", "bar") | ||
|
||
span.set_metric("foo", "bar") | ||
end | ||
end | ||
end |
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
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
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