Skip to content

Fix failing context aware spec

Alex Buijs requested to merge fix-failing-context-aware-spec into master

What does this MR do?

When running bundle exec rspec spec/services/ci/pipeline_trigger_service_spec.rb spec/lib/gitlab/sidekiq_queue_spec.rb together, we get this spec failure: #326547 (closed).

The cause is a missing :context_aware flag in spec/services/ci/pipeline_trigger_service_spec.rb, because it calls code which changes the Gitlab::ApplicationContext, which is tested by spec/lib/gitlab/sidekiq_queue_spec.rb.

We can prevent a leaking application context by annotating a spec that calls Gitlab::ApplicationContext.push with a :context_aware flag.

Note that we used to wrap each spec in its own Labkit::Context. Because this added overhead for all tests and creating a fresh context is unnecessary for mosts tests, we removed that here. Currently we control wrapping controller, request, feature and context_aware annotated tests or just context_aware annotated tests with a fresh context with an environment variable (SKIP_RSPEC_CONTEXT_WRAPPING). Setting that variable to false won't fix this error, since the Ci::PipelineTriggerService spec is a service.

This MR adds the missing flag.

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Alex Buijs

Merge request reports

Loading