Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec/tools/long_running_spec_reporter_spec.rb')
-rw-r--r--qa/spec/tools/long_running_spec_reporter_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/qa/spec/tools/long_running_spec_reporter_spec.rb b/qa/spec/tools/long_running_spec_reporter_spec.rb
new file mode 100644
index 00000000000..1bf520c53af
--- /dev/null
+++ b/qa/spec/tools/long_running_spec_reporter_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Tools::LongRunningSpecReporter do
+ include QA::Support::Helpers::StubEnv
+
+ subject(:reporter) { described_class.execute }
+
+ let(:gcs_client) { double("Fog::Storage::GoogleJSON", get_object: report) }
+ let(:slack_notifier) { double("Slack::Notifier", post: nil) }
+
+ before do
+ stub_env("SLACK_WEBHOOK", "slack_url")
+ stub_env("QA_KNAPSACK_REPORT_GCS_CREDENTIALS", "gcs_json")
+
+ allow(Fog::Storage::Google).to receive(:new)
+ .with(google_project: "gitlab-qa-resources", google_json_key_string: "gcs_json")
+ .and_return(gcs_client)
+ allow(Slack::Notifier).to receive(:new)
+ .with("slack_url", channel: "#quality-reports", username: "Spec Runtime Report")
+ .and_return(slack_notifier)
+ end
+
+ context "without specs exceeding runtime" do
+ let(:report) do
+ {
+ body: <<~JSON
+ {
+ "spec.rb": 5,
+ "spec_2.rb": 10
+ }
+ JSON
+ }
+ end
+
+ it "returns all good message" do
+ expect { reporter }.to output("No long running specs detected, all good!\n").to_stdout
+ end
+ end
+
+ context "with specs exceeding runtime" do
+ let(:report) do
+ {
+ body: <<~JSON
+ {
+ "spec.rb": 5.0,
+ "spec_2.rb": 320.0
+ }
+ JSON
+ }
+ end
+
+ let(:spec) { "spec_2.rb: 5.33 minutes" }
+
+ let(:message) do
+ <<~MSG
+ Following spec files are exceeding 5 minute runtime threshold!
+ Current average spec runtime: 5 seconds.
+ MSG
+ end
+
+ it "notifies on long running specs" do
+ expect { reporter }.to output("#{message}\n#{spec}\n").to_stdout
+ expect(slack_notifier).to have_received(:post).with(
+ icon_emoji: ":time-out:",
+ text: "#{message}\n```#{spec}```"
+ )
+ end
+ end
+end