Skip to content

Unify licensed_feature_available? cache behavior

What does this MR do

Unify licensed_feature_available? cache behavior in project and namespace.

ClearLicensedFeatureAvailableCache is a helper module, it is to eliminate the interference of the cache between the various unit test cases.

JH wants to expand these license caches ( GitlabSubscriptions::Features ), unifying them will make the later work easier.

Code details

The core changes are in these two files:

  • ee/app/models/ee/namespace.rb
  • ee/spec/support/helpers/ee/license_helpers.rb

The purpose of those changes is to make the Namespace cache behave in the same way as Project , especially in tests.

Specifically, it is to clear the cache before unit testing, to eliminate the direct interference of different test cases.

And, Project has done this before. The previous behavior of Namespace was to manually clear the cache when necessary.

Other code is to modify the test to accommodate such modification: there are 7 failed cases ( https://gitlab.com/gitlab-jh/jh-team/gitlab/-/pipelines/523293336/failures ) .

For ease of code review, the reasons and modifications for each case are explained below:

ee/spec/views/layouts/nav/sidebar/_group.html.haml_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618349

spec/support/helpers/rendered_helpers.rb and spec/support/helpers/rendered_helpers.rb

are also written for it, adding a more concise way of writing render expect: is_rendered (like is_expected ).

The more core modification here is to unify the alllow mock methods as stub_licensed_features.

And move special conditions into specific needs tests, such as should_check_namespace_plan?.

ee/spec/support/shared_contexts/requests/api/members_shared_contexts.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618362

Move stub_licensed_features(group_saml: true) after add_maintainer operations,

otherwise, add_maintainer will fail.

ee/spec/requests/groups/group_members_controller_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618362

To prepare the data for for a user with an un-verified email belonging to a domain, member_user and member needs to be created in advance.

spec/graphql/resolvers/issues_resolver_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618298

Update count of batch_sync.

ee/spec/services/boards/epics/create_service_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618345

Bug test case caused by not clearing the cache.

ee/spec/services/projects/transfer_service_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618348

Bug test case caused by not clearing the cache.

ee/spec/models/ee/namespace_spec.rb

https://gitlab.com/gitlab-jh/jh-team/gitlab/-/jobs/2369618355

Remove useless test case.


Related MR: !53278 (merged)

cc EM @prajnamas

Edited by Baodong

Merge request reports

Loading