lib/datadog/ci/test_suite.rb in datadog-ci-0.6.0 vs lib/datadog/ci/test_suite.rb in datadog-ci-0.7.0
- old
+ new
@@ -11,15 +11,66 @@
#
# This object can be shared between multiple threads.
#
# @public_api
class TestSuite < ConcurrentSpan
+ def initialize(tracer_span)
+ super
+
+ @test_suite_stats = Hash.new(0)
+ end
+
# Finishes this test suite.
# @return [void]
def finish
- super
+ synchronize do
+ # we try to derive test suite status from execution stats if no status was set explicitly
+ set_status_from_stats! if undefined?
- CI.deactivate_test_suite(name)
+ super
+
+ recorder.deactivate_test_suite(name)
+ end
+ end
+
+ # @internal
+ def record_test_result(datadog_test_status)
+ synchronize do
+ @test_suite_stats[datadog_test_status] += 1
+ end
+ end
+
+ # @internal
+ def passed_tests_count
+ synchronize do
+ @test_suite_stats[Ext::Test::Status::PASS]
+ end
+ end
+
+ # @internal
+ def skipped_tests_count
+ synchronize do
+ @test_suite_stats[Ext::Test::Status::SKIP]
+ end
+ end
+
+ # @internal
+ def failed_tests_count
+ synchronize do
+ @test_suite_stats[Ext::Test::Status::FAIL]
+ end
+ end
+
+ private
+
+ def set_status_from_stats!
+ if failed_tests_count > 0
+ failed!
+ elsif passed_tests_count == 0
+ skipped!
+ else
+ passed!
+ end
end
end
end
end