[E2E] Harden merge request analytics spec
What does this MR do and why?
[E2E] Harden merge request analytics spec
The Merge Request Analytics spec relies on adding a user to a group, but these permissions are applied async. I suspect that this can lead to situations where the job hasn't processed prior to the attempt to create the project in the group which can cause 403 Forbidden errors. To mitigate against this type of flake in the test, let's ensure we retry to give some allowances for if the processing of the job needs some additional time
Fixes #427897 (closed)
How to set up and validate locally
bundle exec rspec qa/specs/features/ee/browser_ui/2_plan/analytics/mr_analytics_spec.rb:48
- In order to verify that this works when the async job is slow, I found it useful to apply some logic to simulate a sleep in sidekiq. This allowed for recreating the error as described in #427897 (closed) repeatedly, and with this fix applied, the test now gracefully handles this situation.
Suggested diff
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index 8df12671f265..39cdea7e73f7 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
module SidekiqLogArguments
def self.enabled?
Gitlab::Utils.to_boolean(ENV['SIDEKIQ_LOG_ARGUMENTS'], default: true)
@@ -32,7 +33,17 @@ def enable_semi_reliable_fetch_mode?
enable_json_logs = Gitlab.config.sidekiq.log_format != 'text'
+class DelayedProcessingMiddleware
+ def call(_worker, _job, _queue)
+ sleep(2)
+ yield
+ end
+end
+
Sidekiq.configure_server do |config|
+ config.server_middleware do |chain|
+ chain.add DelayedProcessingMiddleware
+ end
config[:strict] = false
config[:queues] = Gitlab::SidekiqConfig.expand_queues(config[:queues])
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by John McDonnell