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
let(:url_to_repo) { "#{primary.url}#{project.full_path}.design.git" }
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("geo_project_housekeeping:#{project.id}")
......
......@@ -9,14 +9,16 @@ describe Gitlab::ApplicationContext do
end
it 'passes the expected context on to labkit' do
user = build(:user)
project = build(:project)
fake_proc = duck_type(:call)
expected_context = hash_including(user: fake_proc, project: fake_proc, root_namespace: fake_proc)
expect(Labkit::Context).to receive(:with_context).with(expected_context)
described_class.with_context(
user: build(:user),
project: build(:project),
user: user,
project: project,
namespace: build(:namespace)) {}
end
......
......@@ -165,10 +165,10 @@ RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do
ActiveSession.set(user, request)
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:lookup:user:gitlab:#{user.id}"
]
)
end
end
......
......@@ -1221,6 +1221,10 @@ describe User, :do_not_mock_admin_mode do
end
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')
user = create(:user)
......
......@@ -30,7 +30,7 @@ describe Users::ActivityService do
end
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
end
......@@ -56,7 +56,7 @@ describe Users::ActivityService do
end
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
end
......
......@@ -52,6 +52,8 @@ describe ClusterUpdateAppWorker do
let(:lease_key) { "#{described_class.name.underscore}-#{application.id}" }
before do
# update_highest_role uses exclusive key too:
allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original
stub_exclusive_lease_taken(lease_key)
end
......@@ -62,8 +64,6 @@ describe ClusterUpdateAppWorker do
end
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))
expect(Clusters::Applications::PrometheusUpdateService).not_to receive(:new)
......@@ -87,8 +87,6 @@ describe ClusterUpdateAppWorker do
application2 = create(:clusters_applications_prometheus, :installed)
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))
stub_exclusive_lease(lease_key2)
......
......@@ -30,9 +30,11 @@ describe NewIssueWorker do
end
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')
worker.perform(create(:issue).id, 99)
worker.perform(issue.id, 99)
end
end
......
......@@ -15,9 +15,11 @@ describe NewMergeRequestWorker do
end
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')
worker.perform(99, create(:user).id)
worker.perform(99, user.id)
end
end
......@@ -30,9 +32,11 @@ describe NewMergeRequestWorker do
end
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')
worker.perform(create(:merge_request).id, 99)
worker.perform(merge_request.id, 99)
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