Commit 7452dd22 authored by rpereira2's avatar rpereira2

Make create_environment method idempotent

Add spec to ensure that the SelfMonitoring::CreateService is idempotent.
parent e2ce3c1a
...@@ -91,6 +91,8 @@ module Gitlab ...@@ -91,6 +91,8 @@ module Gitlab
end end
def create_environment(result) def create_environment(result)
return success(result) if result[:project].environments.exists?
environment = ::Environment.new(project_id: result[:project].id, name: 'production') environment = ::Environment.new(project_id: result[:project].id, name: 'production')
if environment.save if environment.save
......
...@@ -76,6 +76,14 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -76,6 +76,14 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it_behaves_like 'has prometheus service', 'http://localhost:9090' 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 it "tracks successful install" do
expect(::Gitlab::Tracking).to receive(:event).twice expect(::Gitlab::Tracking).to receive(:event).twice
expect(::Gitlab::Tracking).to receive(:event).with('self_monitoring', 'project_created') 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