Commit 4f0144e0 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'make-self-monitoring-create-service-idempotent' into 'master'

Make create_environment method idempotent

See merge request gitlab-org/gitlab!24866
parents 85d61394 7452dd22
......@@ -91,6 +91,8 @@ module Gitlab
end
def create_environment(result)
return success(result) if result[:project].environments.exists?
environment = ::Environment.new(project_id: result[:project].id, name: 'production')
if environment.save
......
......@@ -76,6 +76,14 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it_behaves_like 'has prometheus service', 'http://localhost:9090'
it 'is idempotent' do
result1 = subject.execute
expect(result1[:status]).to eq(:success)
result2 = subject.execute
expect(result2[:status]).to eq(:success)
end
it "tracks successful install" do
expect(::Gitlab::Tracking).to receive(:event).twice
expect(::Gitlab::Tracking).to receive(:event).with('self_monitoring', 'project_created')
......
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