Commit d1cc45fd authored by Corinna Wiesner's avatar Corinna Wiesner

Fix failing specs due to triggered User callback

The failing specs triggered the User callback to update the highest role
which tries to create an exclusive lease which causes the specs to fail.
parent d1713c27
...@@ -28,7 +28,8 @@ describe Geo::DesignRepositorySyncService do ...@@ -28,7 +28,8 @@ describe Geo::DesignRepositorySyncService do
let(:url_to_repo) { "#{primary.url}#{project.full_path}.design.git" } let(:url_to_repo) { "#{primary.url}#{project.full_path}.design.git" }
before do before do
allow_any_instance_of(Member).to receive(:update_highest_role) # avoid stubbing exclusive lease for this method # update_highest_role uses exclusive key too:
allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original
stub_exclusive_lease(lease_key, lease_uuid) stub_exclusive_lease(lease_key, lease_uuid)
stub_exclusive_lease("geo_project_housekeeping:#{project.id}") stub_exclusive_lease("geo_project_housekeeping:#{project.id}")
......
...@@ -9,14 +9,16 @@ describe Gitlab::ApplicationContext do ...@@ -9,14 +9,16 @@ describe Gitlab::ApplicationContext do
end end
it 'passes the expected context on to labkit' do it 'passes the expected context on to labkit' do
user = build(:user)
project = build(:project)
fake_proc = duck_type(:call) fake_proc = duck_type(:call)
expected_context = hash_including(user: fake_proc, project: fake_proc, root_namespace: fake_proc) expected_context = hash_including(user: fake_proc, project: fake_proc, root_namespace: fake_proc)
expect(Labkit::Context).to receive(:with_context).with(expected_context) expect(Labkit::Context).to receive(:with_context).with(expected_context)
described_class.with_context( described_class.with_context(
user: build(:user), user: user,
project: build(:project), project: project,
namespace: build(:namespace)) {} namespace: build(:namespace)) {}
end end
......
...@@ -165,10 +165,10 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do ...@@ -165,10 +165,10 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
ActiveSession.set(user, request) ActiveSession.set(user, request)
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::SharedState.with do |redis|
expect(redis.scan_each.to_a).to match_array [ expect(redis.scan_each.to_a).to include(
"session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d", "session:user:gitlab:#{user.id}:6919a6f1bb119dd7396fadc38fd18d0d",
"session:lookup:user:gitlab:#{user.id}" "session:lookup:user:gitlab:#{user.id}"
] )
end end
end end
......
...@@ -1221,6 +1221,10 @@ describe User, :do_not_mock_admin_mode do ...@@ -1221,6 +1221,10 @@ describe User, :do_not_mock_admin_mode do
end end
it 'uses SecureRandom to generate the incoming email token' do it 'uses SecureRandom to generate the incoming email token' do
allow_next_instance_of(User) do |user|
allow(user).to receive(:update_highest_role)
end
expect(SecureRandom).to receive(:hex).and_return('3b8ca303') expect(SecureRandom).to receive(:hex).and_return('3b8ca303')
user = create(:user) user = create(:user)
......
...@@ -30,7 +30,7 @@ describe Users::ActivityService do ...@@ -30,7 +30,7 @@ describe Users::ActivityService do
end end
it 'tries to obtain ExclusiveLease' do it 'tries to obtain ExclusiveLease' do
expect(Gitlab::ExclusiveLease).to receive(:new).and_call_original expect(Gitlab::ExclusiveLease).to receive(:new).with("activity_service:#{user.id}", anything).and_call_original
subject.execute subject.execute
end end
...@@ -56,7 +56,7 @@ describe Users::ActivityService do ...@@ -56,7 +56,7 @@ describe Users::ActivityService do
end end
it 'does not try to obtain ExclusiveLease' do it 'does not try to obtain ExclusiveLease' do
expect(Gitlab::ExclusiveLease).not_to receive(:new) expect(Gitlab::ExclusiveLease).not_to receive(:new).with("activity_service:#{user.id}", anything)
subject.execute subject.execute
end end
......
...@@ -52,6 +52,8 @@ describe ClusterUpdateAppWorker do ...@@ -52,6 +52,8 @@ describe ClusterUpdateAppWorker do
let(:lease_key) { "#{described_class.name.underscore}-#{application.id}" } let(:lease_key) { "#{described_class.name.underscore}-#{application.id}" }
before do before do
# update_highest_role uses exclusive key too:
allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original
stub_exclusive_lease_taken(lease_key) stub_exclusive_lease_taken(lease_key)
end end
...@@ -62,8 +64,6 @@ describe ClusterUpdateAppWorker do ...@@ -62,8 +64,6 @@ describe ClusterUpdateAppWorker do
end end
it 'does not allow same app to be updated concurrently by different project', :aggregate_failures do it 'does not allow same app to be updated concurrently by different project', :aggregate_failures do
stub_exclusive_lease("refresh_authorized_projects:#{user.id}")
stub_exclusive_lease("update_highest_role:#{user.id}")
project1 = create(:project, namespace: create(:namespace, owner: user)) project1 = create(:project, namespace: create(:namespace, owner: user))
expect(Clusters::Applications::PrometheusUpdateService).not_to receive(:new) expect(Clusters::Applications::PrometheusUpdateService).not_to receive(:new)
...@@ -87,8 +87,6 @@ describe ClusterUpdateAppWorker do ...@@ -87,8 +87,6 @@ describe ClusterUpdateAppWorker do
application2 = create(:clusters_applications_prometheus, :installed) application2 = create(:clusters_applications_prometheus, :installed)
lease_key2 = "#{described_class.name.underscore}-#{application2.id}" lease_key2 = "#{described_class.name.underscore}-#{application2.id}"
stub_exclusive_lease("refresh_authorized_projects:#{user.id}")
stub_exclusive_lease("update_highest_role:#{user.id}")
project2 = create(:project, namespace: create(:namespace, owner: user)) project2 = create(:project, namespace: create(:namespace, owner: user))
stub_exclusive_lease(lease_key2) stub_exclusive_lease(lease_key2)
......
...@@ -30,9 +30,11 @@ describe NewIssueWorker do ...@@ -30,9 +30,11 @@ describe NewIssueWorker do
end end
it 'logs an error' do it 'logs an error' do
issue = create(:issue)
expect(Rails.logger).to receive(:error).with('NewIssueWorker: couldn\'t find User with ID=99, skipping job') expect(Rails.logger).to receive(:error).with('NewIssueWorker: couldn\'t find User with ID=99, skipping job')
worker.perform(create(:issue).id, 99) worker.perform(issue.id, 99)
end end
end end
......
...@@ -15,9 +15,11 @@ describe NewMergeRequestWorker do ...@@ -15,9 +15,11 @@ describe NewMergeRequestWorker do
end end
it 'logs an error' do it 'logs an error' do
user = create(:user)
expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find MergeRequest with ID=99, skipping job') expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find MergeRequest with ID=99, skipping job')
worker.perform(99, create(:user).id) worker.perform(99, user.id)
end end
end end
...@@ -30,9 +32,11 @@ describe NewMergeRequestWorker do ...@@ -30,9 +32,11 @@ describe NewMergeRequestWorker do
end end
it 'logs an error' do it 'logs an error' do
merge_request = create(:merge_request)
expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find User with ID=99, skipping job') expect(Rails.logger).to receive(:error).with('NewMergeRequestWorker: couldn\'t find User with ID=99, skipping job')
worker.perform(create(:merge_request).id, 99) worker.perform(merge_request.id, 99)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment