Skip to content
代码片段 群组 项目
未验证 提交 b442732d 编辑于 作者: Rémy Coutable's avatar Rémy Coutable 提交者: GitLab
浏览文件

Merge branch 'ddieulivol-add_logging_for_rspec_flaky' into 'master'

Add message when known flaky examples were found

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/141610



Merged-by: default avatarRémy Coutable <remy@rymai.me>
Approved-by: default avatarRémy Coutable <remy@rymai.me>
Reviewed-by: default avatarRémy Coutable <remy@rymai.me>
Co-authored-by: default avatarddieulivol <ddieulivol@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -36,6 +36,10 @@ def example_passed(notification) ...@@ -36,6 +36,10 @@ def example_passed(notification)
end end
def dump_summary(_) def dump_summary(_)
rails_logger_warn(
"\n#{flaky_examples.count} known flaky example(s) detected. " \
"Writing this to #{Config.flaky_examples_report_path}.\n"
)
Report.new(flaky_examples).write(Config.flaky_examples_report_path) Report.new(flaky_examples).write(Config.flaky_examples_report_path)
return unless new_flaky_examples.any? return unless new_flaky_examples.any?
......
...@@ -197,6 +197,8 @@ ...@@ -197,6 +197,8 @@
end end
describe '#dump_summary' do describe '#dump_summary' do
subject { listener.dump_summary(nil) }
let(:listener) { described_class.new(suite_flaky_example_report.to_json) } let(:listener) { described_class.new(suite_flaky_example_report.to_json) }
let(:new_flaky_rspec_example) { double(new_example_attrs.merge(attempts: 2)) } let(:new_flaky_rspec_example) { double(new_example_attrs.merge(attempts: 2)) }
let(:already_flaky_rspec_example) { double(already_flaky_example_attrs.merge(attempts: 2)) } let(:already_flaky_rspec_example) { double(already_flaky_example_attrs.merge(attempts: 2)) }
...@@ -207,6 +209,39 @@ ...@@ -207,6 +209,39 @@
allow(Kernel).to receive(:warn) allow(Kernel).to receive(:warn)
end end
context 'when not flaky tests were found' do
it 'prints a message in the console' do
allow(Kernel).to receive(:warn).and_call_original
expect { subject }.to output(
%r{0 known flaky example\(s\) detected\. Writing this to rspec/flaky/report\.json}
).to_stderr
end
end
context 'when existing flaky tests were found' do
before do
listener.example_passed(notification_already_flaky_rspec_example)
end
it 'does write them in the correct report' do
report = double
expect(Gitlab::RspecFlaky::Report).to receive(:new).with(listener.flaky_examples).and_return(report)
expect(report).to receive(:write).with(Gitlab::RspecFlaky::Config.flaky_examples_report_path)
subject
end
it 'prints a message in the console' do
allow(Kernel).to receive(:warn).and_call_original
expect { subject }.to output(
%r{1 known flaky example\(s\) detected\. Writing this to rspec/flaky/report\.json}
).to_stderr
end
end
context 'when a report file path is set by FLAKY_RSPEC_REPORT_PATH' do context 'when a report file path is set by FLAKY_RSPEC_REPORT_PATH' do
it 'delegates the writes to RspecFlaky::Report' do it 'delegates the writes to RspecFlaky::Report' do
listener.example_passed(notification_new_flaky_rspec_example) listener.example_passed(notification_new_flaky_rspec_example)
...@@ -222,7 +257,7 @@ ...@@ -222,7 +257,7 @@
.to receive(:new).with(listener.__send__(:new_flaky_examples)).and_return(report2) .to receive(:new).with(listener.__send__(:new_flaky_examples)).and_return(report2)
expect(report2).to receive(:write).with(Gitlab::RspecFlaky::Config.new_flaky_examples_report_path) expect(report2).to receive(:write).with(Gitlab::RspecFlaky::Config.new_flaky_examples_report_path)
listener.dump_summary(nil) subject
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册