saas_user_registration_spec failures on `master`
Context
More in https://gitlab.slack.com/archives/C3JJET4Q6/p1651749265982319
The issue
./ee/spec/features/registrations/saas_user_registration_spec.rb
fails on master
(if to run the full file - important)
1.1) Failure/Error: return yield unless new(admin).admin_mode?
#<GitlabSubscriptions::ApplyTrialService:0x0000000155274920> received :execute with unexpected arguments
expected: ({:trial_user=>#<ActionController::Parameters {"namespace_id"=>182, "gitlab_com_trial"=>true, "sync_to_gl"=>true} permitted: true>, :uid=>68})
got: ({:trial_user=>#<ActionController::Parameters {"namespace_id"=>186, "gitlab_com_trial"=>true, "sync_to_gl"=>true} permitted: true>, :uid=>68})
Diff:
@@ -1,4 +1,4 @@
[{:trial_user=>
- #<ActionController::Parameters {"namespace_id"=>182, "gitlab_com_trial"=>true, "sync_to_gl"=>true} permitted: true>,
+ #<ActionController::Parameters {"namespace_id"=>186, "gitlab_com_trial"=>true, "sync_to_gl"=>true} permitted: true>,
:uid=>68}]
# ./ee/app/controllers/concerns/registrations/apply_trial.rb:19:in `apply_trial'
# ./ee/app/controllers/registrations/groups_projects_controller.rb:127:in `apply_trial_when_in_trial_flow'
# ./ee/app/controllers/registrations/groups_projects_controller.rb:42:in `create'
# ./ee/lib/gitlab/ip_address_state.rb:10:in `with'
# ./ee/app/controllers/ee/application_controller.rb:45:in `set_current_ip_address'
As you could see the issue is with the namespace_id
being incorrect.
It fails on CI as well (https://gitlab.com/gitlab-org/gitlab/-/jobs/2417042796), but CI retries single example and it passes when run like that.
The cause of the failure may be a side effect with Namespace
entities being populated after the Namespace.maximum(:id).to_i + 1
is calculated. That's why running only a single example passes.
Other notes
Talking about the test design, it feels that any assumptions on the namespace_id
value should lie outside of the system
specs domain.
ID is calculated by the Database.
Although it happens in a rather predictable fashion, but it's still a different system. In my opinion, we shouldn't make any hard assumptions on how DB internals work (which could be done in unit tests), because we are testing a higher level in system specs.