Skip to content

Commit 3e6166d

Browse files
committed
fix: concurrent context tests are removed in unit/actions. Uniqueness tests are reintroduced in unit/models.
1 parent 8c7d5ed commit 3e6166d

14 files changed

Lines changed: 70 additions & 110 deletions

spec/unit/actions/organization_create_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,23 +110,6 @@ module VCAP::CloudController
110110
end.to raise_error(OrganizationCreate::Error, "Organization '#{name}' already exists.")
111111
end
112112
end
113-
114-
context 'when creating organizations concurrently' do
115-
let(:name) { 'Alfredo' }
116-
117-
it 'ensures one creation is successful and the other fails due to name conflict' do
118-
# First request, should succeed
119-
message = VCAP::CloudController::OrganizationUpdateMessage.new(name:)
120-
expect do
121-
org_create.create(message)
122-
end.not_to raise_error
123-
124-
# Second request, should fail with correct error
125-
expect do
126-
org_create.create(message)
127-
end.to raise_error(OrganizationCreate::Error, "Organization 'Alfredo' already exists.")
128-
end
129-
end
130113
end
131114
end
132115
end

spec/unit/actions/service_broker_create_spec.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,6 @@ module CloudController
132132
end
133133
end
134134
end
135-
136-
describe 'when creating a service broker with the same name concurrently' do
137-
it 'ensures one creation is successful and the other fails due to name conflict' do
138-
# First request, should succeed
139-
expect do
140-
action.create(message)
141-
end.not_to raise_error
142-
143-
# Second request, should fail with correct error
144-
expect do
145-
action.create(message)
146-
end.to raise_error(V3::ServiceBrokerCreate::InvalidServiceBroker)
147-
end
148-
end
149135
end
150136
end
151137
end

spec/unit/actions/space_create_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,6 @@ module VCAP::CloudController
7979
end.to raise_error(SpaceCreate::Error, 'Name must be unique per organization')
8080
end
8181
end
82-
83-
context 'when creating spaces concurrently' do
84-
let(:name) { 'Rose' }
85-
86-
it 'ensures one creation is successful and the other fails due to name conflict' do
87-
# First request, should succeed
88-
message = VCAP::CloudController::SpaceCreateMessage.new(name:)
89-
expect do
90-
SpaceCreate.new(user_audit_info:).create(org, message)
91-
end.not_to raise_error
92-
93-
# Second request, should fail with correct error
94-
expect do
95-
SpaceCreate.new(user_audit_info:).create(org, message)
96-
end.to raise_error(SpaceCreate::Error, 'Name must be unique per organization')
97-
end
98-
end
9982
end
10083
end
10184
end

spec/unit/actions/space_quotas_create_spec.rb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,6 @@ module VCAP::CloudController
202202
end
203203
end
204204
end
205-
206-
context 'when creating space quota with the same name concurrently' do
207-
it 'ensures one creation is successful and the other fails due to name conflict' do
208-
# First request, should succeed
209-
expect do
210-
space_quotas_create.create(message, organization: org)
211-
end.not_to raise_error
212-
213-
# Second request, should fail with correct error
214-
expect do
215-
space_quotas_create.create(message, organization: org)
216-
end.to raise_error(SpaceQuotasCreate::Error, "Space Quota 'my-name' already exists.")
217-
end
218-
end
219205
end
220206
end
221207
end

spec/unit/actions/stack_create_spec.rb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,6 @@ module VCAP::CloudController
119119
end.to raise_error(StackCreate::Error, 'Name must be unique')
120120
end
121121
end
122-
123-
context 'when creating stack with the same name concurrently' do
124-
let(:name) { 'Gaby' }
125-
126-
it 'ensures one creation is successful and the other fails due to name conflict' do
127-
message = VCAP::CloudController::StackCreateMessage.new(name:)
128-
# First request, should succeed
129-
expect do
130-
stack_create.create(message)
131-
end.not_to raise_error
132-
133-
# Second request, should fail with correct error
134-
expect do
135-
stack_create.create(message)
136-
end.to raise_error(StackCreate::Error, 'Name must be unique')
137-
end
138-
end
139122
end
140123
end
141124
end

spec/unit/actions/user_create_spec.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ module VCAP::CloudController
3535
end
3636
end
3737

38-
context 'when creating users concurrently' do
39-
let(:message) { UserCreateMessage.new({ guid: 'some-nice-user-gu-id' }) }
40-
41-
it 'ensures one creation is successful and the other fails due to name conflict' do
42-
# First request, should succeed
43-
expect do
44-
subject.create(message:)
45-
end.not_to raise_error
46-
47-
# Second request, should fail with correct error
48-
expect do
49-
subject.create(message:)
50-
end.to raise_error(UserCreate::Error, "User with guid 'some-nice-user-gu-id' already exists.")
51-
end
52-
end
53-
5438
describe 'creating users' do
5539
before do
5640
allow(User).to receive_messages(create_uaa_shadow_user: { 'id' => guid }, get_user_id_by_username_and_origin: nil)

spec/unit/isolation_segment_create_spec.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,6 @@ module VCAP::CloudController
4444
end.to raise_error(IsolationSegmentCreate::Error, 'blork is busted')
4545
end
4646
end
47-
48-
context 'when creating isolation segments concurrently' do
49-
it 'ensures one creation is successful and the other fails due to name conflict' do
50-
# First request, should succeed
51-
message = VCAP::CloudController::IsolationSegmentCreateMessage.new(name: 'foobar')
52-
expect do
53-
IsolationSegmentCreate.create(message)
54-
end.not_to raise_error
55-
56-
# Second request, should fail with correct error
57-
expect do
58-
IsolationSegmentCreate.create(message)
59-
end.to raise_error(IsolationSegmentCreate::Error, 'Isolation Segment names are case insensitive and must be unique')
60-
end
61-
end
6247
end
6348
end
6449
end

spec/unit/models/runtime/isolation_segment_model_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ module VCAP::CloudController
124124
end.to raise_error(Sequel::ValidationFailed, 'Isolation Segment names can only contain non-blank unicode characters')
125125
end
126126

127+
it 'requires a unique name' do
128+
IsolationSegmentModel.make(name: 'segment1')
129+
130+
expect do
131+
IsolationSegmentModel.make(name: 'segment1')
132+
end.to raise_error(Sequel::ValidationFailed, 'Isolation Segment names are case insensitive and must be unique')
133+
end
134+
135+
it 'uniqueness is case insensitive' do
136+
IsolationSegmentModel.make(name: 'lowercase')
137+
138+
expect do
139+
IsolationSegmentModel.make(name: 'lowerCase')
140+
end.to raise_error(Sequel::ValidationFailed, 'Isolation Segment names are case insensitive and must be unique')
141+
end
142+
127143
it 'allows standard ascii characters' do
128144
expect do
129145
IsolationSegmentModel.make(name: "A -_- word 2!?()'\"&+.")

spec/unit/models/runtime/organization_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ module VCAP::CloudController
121121
end
122122
end
123123

124+
describe 'uniqueness' do
125+
it 'enforces uniqueness of name' do
126+
existing_org = Organization.make
127+
expect do
128+
Organization.create(name: existing_org.name)
129+
end.to raise_error(Sequel::ValidationFailed, /unique/)
130+
end
131+
end
132+
124133
describe 'Validations' do
125134
let(:org) { Organization.make }
126135

spec/unit/models/runtime/space_quota_definition_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ module VCAP::CloudController
1717
end
1818
end
1919

20+
describe 'uniqueness' do
21+
it 'enforces uniqueness of name within an organization' do
22+
existing_quota = SpaceQuotaDefinition.make
23+
expect do
24+
SpaceQuotaDefinition.make(name: existing_quota.name, organization: existing_quota.organization)
25+
end.to raise_error(Sequel::ValidationFailed, /unique/)
26+
end
27+
end
28+
2029
describe 'Validations' do
2130
it { is_expected.to validate_presence :name }
2231
it { is_expected.to validate_presence :non_basic_services_allowed }

0 commit comments

Comments
 (0)