Skip to content

Commit

Permalink
unit tests for setting and removing test_finished_callback in test vi…
Browse files Browse the repository at this point in the history
…sibility
  • Loading branch information
anmarchenko committed Aug 9, 2024
1 parent a02d023 commit 067c735
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions spec/datadog/ci/test_visibility/component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,4 +797,51 @@
end
end
end

describe "#set_test_finished_callback" do
include_context "CI mode activated"

let(:callback) { spy(:callback) }

it "sets the test finished callback which will be executed when any test is finished" do
test_visibility.set_test_finished_callback(callback)

ci_test = test_visibility.trace_test("my test", "my suite")
test_visibility.deactivate_test

expect(callback).to have_received(:call).with(ci_test)
end

it "only fires callback on the same thread where it was set" do
test_visibility.set_test_finished_callback(callback)

t = Thread.new do
test_visibility.trace_test("my test", "my suite")
test_visibility.deactivate_test
end
t.join

expect(callback).to_not have_received(:call)
end
end

describe "#remove_test_finished_callback" do
include_context "CI mode activated"

let(:callback) { spy(:callback) }

it "removes the callback" do
test_visibility.set_test_finished_callback(callback)

test_visibility.trace_test("my test", "my suite")
test_visibility.deactivate_test

test_visibility.remove_test_finished_callback

test_visibility.trace_test("my test", "my suite")
test_visibility.deactivate_test

expect(callback).to have_received(:call).once
end
end
end

0 comments on commit 067c735

Please sign in to comment.