Skip to content

Commit 6db729b

Browse files
committed
RCBC-464: Improve stability of management tests
1 parent 1ae3d35 commit 6db729b

9 files changed

+258
-14
lines changed

bin/jenkins/test-with-cbdyncluster

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ fi
5353
CLUSTER_ID=$(cbdyncluster allocate --num-nodes=3 --server-version=${CB_VERSION})
5454
SERVICES="kv,index,n1ql,fts"
5555
CB_BUCKET=default
56-
cbdyncluster setup ${CLUSTER_ID} \
56+
CLUSTER_ENTRY_POINT=$(cbdyncluster setup ${CLUSTER_ID} \
57+
--ram-quota=2048 \
5758
--storage-mode=plasma \
5859
${extra_options} \
5960
--node=${SERVICES} \
6061
--node=${SERVICES} \
61-
--node=${SERVICES}
62+
--node=${SERVICES})
6263
cbdyncluster add-bucket ${CLUSTER_ID} \
6364
--name default \
6465
--ram-quota 256 \
@@ -121,6 +122,7 @@ then
121122
fi
122123
export TEST_SERVER_VERSION=${CB_VERSION}
123124
export TEST_CONNECTION_STRING=$(cbdyncluster connstr ${CLUSTER_ID})
125+
export TEST_MANAGEMENT_ENDPOINT=${CLUSTER_ENTRY_POINT}
124126
set +e
125127

126128
cat /proc/sys/kernel/core_pattern

test/bucket_manager_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def test_create_bucket_history_retention
5454
s.history_retention_duration = 600
5555
end
5656
)
57+
58+
env.consistency.wait_until_bucket_present(bucket_name)
59+
5760
res = @bucket_manager.get_bucket(bucket_name)
5861

5962
refute res.history_retention_collection_default
@@ -91,6 +94,9 @@ def test_update_bucket_history_retention
9194
s.ram_quota_mb = 1024
9295
end
9396
)
97+
98+
env.consistency.wait_until_bucket_present(bucket_name)
99+
94100
res = @bucket_manager.get_bucket(bucket_name)
95101

96102
assert res.history_retention_collection_default
@@ -125,6 +131,9 @@ def test_update_bucket_history_retention_unsupported
125131
s.storage_backend = :couchstore
126132
end
127133
)
134+
135+
env.consistency.wait_until_bucket_present(bucket_name)
136+
128137
res = @bucket_manager.get_bucket(bucket_name)
129138

130139
assert_nil res.history_retention_collection_default

test/collection_manager_test.rb

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ def create_magma_bucket
2929
s.ram_quota_mb = 1024
3030
end
3131
)
32-
begin
33-
end
32+
33+
env.consistency.wait_until_bucket_present(TEST_MAGMA_BUCKET_NAME)
34+
3435
retry_for_duration(expected_errors: [Error::BucketNotFound]) do
3536
@magma_bucket = @cluster.bucket(TEST_MAGMA_BUCKET_NAME)
3637
end
@@ -57,6 +58,8 @@ def get_collection(scope_name, collection_name, mgr = nil)
5758
end
5859

5960
def setup
61+
skip("#{name}: The server does not support collections") unless env.server_version.supports_collections?
62+
6063
connect
6164
@used_scopes = []
6265
@bucket = @cluster.bucket(env.bucket)
@@ -86,6 +89,7 @@ def teardown
8689
def test_create_scope
8790
scope_name = get_scope_name
8891
@collection_manager.create_scope(scope_name)
92+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
8993
scope = get_scope(scope_name)
9094

9195
refute_nil scope
@@ -94,11 +98,13 @@ def test_create_scope
9498
def test_drop_scope
9599
scope_name = get_scope_name
96100
@collection_manager.create_scope(scope_name)
101+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
97102
scope = get_scope(scope_name)
98103

99104
refute_nil scope
100105

101106
@collection_manager.drop_scope(scope_name)
107+
env.consistency.wait_until_scope_dropped(env.bucket, scope_name)
102108
scope = get_scope(scope_name)
103109

104110
assert_nil scope
@@ -108,8 +114,11 @@ def test_create_collection
108114
coll_names = %w[coll-1 coll-2 coll-3]
109115
scope_name = get_scope_name
110116
@collection_manager.create_scope(scope_name)
117+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
118+
111119
coll_names.each do |coll_name|
112120
@collection_manager.create_collection(scope_name, coll_name)
121+
env.consistency.wait_until_collection_present(env.bucket, scope_name, coll_name)
113122
end
114123
scope = get_scope(scope_name)
115124

@@ -121,15 +130,20 @@ def test_drop_collection
121130
coll_names = %w[coll-1 coll-2 coll-3]
122131
scope_name = get_scope_name
123132
@collection_manager.create_scope(scope_name)
133+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
134+
124135
coll_names.each do |coll_name|
125136
@collection_manager.create_collection(scope_name, coll_name)
137+
env.consistency.wait_until_collection_present(env.bucket, scope_name, coll_name)
126138
end
127139
scope = get_scope(scope_name)
128140

129141
refute_nil scope
130142
assert_equal coll_names.sort, scope.collections.map(&:name).sort
131143

132144
@collection_manager.drop_collection(scope_name, 'coll-1')
145+
env.consistency.wait_until_collection_dropped(env.bucket, scope_name, 'coll-1')
146+
133147
scope = get_scope(scope_name)
134148

135149
refute_includes scope.collections.map(&:name), 'coll-1'
@@ -139,7 +153,10 @@ def test_create_collection_already_exists
139153
coll_name = 'coll-1'
140154
scope_name = get_scope_name
141155
@collection_manager.create_scope(scope_name)
156+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
157+
142158
@collection_manager.create_collection(scope_name, coll_name)
159+
env.consistency.wait_until_collection_present(env.bucket, scope_name, coll_name)
143160

144161
refute_nil get_collection(scope_name, coll_name)
145162

@@ -170,6 +187,7 @@ def test_create_collection_scope_does_not_exist
170187
def test_create_scope_already_exists
171188
scope_name = get_scope_name
172189
@collection_manager.create_scope(scope_name)
190+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
173191

174192
refute_nil get_scope(scope_name)
175193

@@ -190,6 +208,7 @@ def test_drop_collection_does_not_exist
190208
scope_name = get_scope_name
191209
coll_name = 'does-not-exist'
192210
@collection_manager.create_scope(scope_name)
211+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
193212

194213
refute_nil get_scope(scope_name)
195214

@@ -216,12 +235,14 @@ def test_create_collection_history_retention
216235
scope_name = get_scope_name
217236
collection_name = 'test-coll'
218237
@magma_collection_manager.create_scope(scope_name)
238+
env.consistency.wait_until_scope_present(TEST_MAGMA_BUCKET_NAME, scope_name)
219239
scope = get_scope(scope_name, @magma_collection_manager)
220240

221241
assert scope
222242

223243
settings = Management::CreateCollectionSettings.new(history: true)
224244
@magma_collection_manager.create_collection(scope_name, collection_name, settings)
245+
env.consistency.wait_until_collection_present(TEST_MAGMA_BUCKET_NAME, scope_name, collection_name)
225246

226247
coll = get_collection(scope_name, collection_name, @magma_collection_manager)
227248

@@ -239,12 +260,15 @@ def test_update_collection_history_retention
239260
scope_name = get_scope_name
240261
collection_name = 'test-coll'
241262
@magma_collection_manager.create_scope(scope_name)
263+
env.consistency.wait_until_scope_present(TEST_MAGMA_BUCKET_NAME, scope_name)
264+
242265
scope = get_scope(scope_name, @magma_collection_manager)
243266

244267
assert scope
245268

246269
settings = Management::CreateCollectionSettings.new(history: false)
247270
@magma_collection_manager.create_collection(scope_name, collection_name, settings)
271+
env.consistency.wait_until_collection_present(TEST_MAGMA_BUCKET_NAME, scope_name, collection_name)
248272

249273
coll = get_collection(scope_name, collection_name, @magma_collection_manager)
250274

@@ -268,6 +292,8 @@ def test_create_collection_history_retention_unsupported
268292
scope_name = get_scope_name
269293
collection_name = 'test-coll'
270294
@collection_manager.create_scope(scope_name)
295+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
296+
271297
scope = get_scope(scope_name)
272298

273299
assert scope
@@ -287,6 +313,8 @@ def test_update_collection_history_retention_unsupported
287313
scope_name = get_scope_name
288314
collection_name = 'test-coll'
289315
@collection_manager.create_scope(scope_name)
316+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
317+
290318
scope = get_scope(scope_name)
291319

292320
assert scope
@@ -309,12 +337,14 @@ def test_create_collection_max_expiry
309337
scope_name = get_scope_name
310338
collection_name = 'testcoll'
311339
@collection_manager.create_scope(scope_name)
340+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
312341
scope = get_scope(scope_name)
313342

314343
assert scope
315344

316345
settings = Management::CreateCollectionSettings.new(max_expiry: 5)
317346
@collection_manager.create_collection(scope_name, collection_name, settings)
347+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
318348

319349
coll_spec = get_collection(scope_name, collection_name)
320350

@@ -348,13 +378,15 @@ def test_create_collection_max_expiry_no_expiry
348378
scope_name = get_scope_name
349379
collection_name = 'testcoll'
350380
@collection_manager.create_scope(scope_name)
381+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
351382
scope = get_scope(scope_name)
352383

353384
assert scope
354385

355386
settings = Management::CreateCollectionSettings.new(max_expiry: -1)
356387

357388
@collection_manager.create_collection(scope_name, collection_name, settings)
389+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
358390

359391
coll_spec = get_collection(scope_name, collection_name)
360392

@@ -369,6 +401,7 @@ def test_create_collection_max_expiry_no_expiry_not_supported
369401
scope_name = get_scope_name
370402
collection_name = 'testcoll'
371403
@collection_manager.create_scope(scope_name)
404+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
372405
scope = get_scope(scope_name)
373406

374407
assert scope
@@ -384,6 +417,7 @@ def test_create_collection_max_expiry_invalid
384417
scope_name = get_scope_name
385418
collection_name = 'testcoll'
386419
@collection_manager.create_scope(scope_name)
420+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
387421
scope = get_scope(scope_name)
388422

389423
assert scope
@@ -404,12 +438,14 @@ def test_update_collection_max_expiry
404438
scope_name = get_scope_name
405439
collection_name = 'test-coll'
406440
@collection_manager.create_scope(scope_name)
441+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
407442
scope = get_scope(scope_name)
408443

409444
assert scope
410445

411446
settings = Management::CreateCollectionSettings.new(max_expiry: 600)
412447
@collection_manager.create_collection(scope_name, collection_name, settings)
448+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
413449

414450
coll_spec = get_collection(scope_name, collection_name)
415451

@@ -451,12 +487,14 @@ def test_update_collection_max_expiry_no_expiry
451487
scope_name = get_scope_name
452488
collection_name = 'testcoll'
453489
@collection_manager.create_scope(scope_name)
490+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
454491
scope = get_scope(scope_name)
455492

456493
assert scope
457494

458495
settings = Management::CreateCollectionSettings.new(max_expiry: 600)
459496
@collection_manager.create_collection(scope_name, collection_name, settings)
497+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
460498

461499
coll_spec = get_collection(scope_name, collection_name)
462500

@@ -475,18 +513,23 @@ def test_update_collection_max_expiry_no_expiry
475513

476514
def test_update_collection_max_expiry_no_expiry_not_supported
477515
skip("#{name}: CAVES does not support update_collection") if use_caves?
516+
unless env.server_version.supports_update_collection_max_expiry?
517+
skip("#{name}: The server does not support update_collection with max_expiry")
518+
end
478519
skip("#{name}: The #{Couchbase::Protostellar::NAME} protocol does not support update_collection") if env.protostellar?
479520
skip("#{name}: The server supports setting max_expiry to -1") if env.server_version.supports_collection_max_expiry_set_to_no_expiry?
480521

481522
scope_name = get_scope_name
482523
collection_name = 'testcoll'
483524
@collection_manager.create_scope(scope_name)
525+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
484526
scope = get_scope(scope_name)
485527

486528
assert scope
487529

488530
settings = Management::CreateCollectionSettings.new(max_expiry: 600)
489531
@collection_manager.create_collection(scope_name, collection_name, settings)
532+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
490533

491534
coll_spec = get_collection(scope_name, collection_name)
492535

@@ -507,12 +550,14 @@ def test_update_collection_max_expiry_invalid
507550
scope_name = get_scope_name
508551
collection_name = 'testcoll'
509552
@collection_manager.create_scope(scope_name)
553+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
510554
scope = get_scope(scope_name)
511555

512556
assert scope
513557

514558
settings = Management::CreateCollectionSettings.new(max_expiry: 600)
515559
@collection_manager.create_collection(scope_name, collection_name, settings)
560+
env.consistency.wait_until_collection_present(env.bucket, scope_name, collection_name)
516561

517562
coll_spec = get_collection(scope_name, collection_name)
518563

@@ -535,6 +580,7 @@ def test_update_collection_does_not_exist
535580
scope_name = get_scope_name
536581
coll_name = 'does-not-exist'
537582
@collection_manager.create_scope(scope_name)
583+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
538584

539585
refute_nil get_scope(scope_name)
540586

@@ -565,13 +611,16 @@ def test_create_collection_deprecated
565611
scope_name = get_scope_name
566612
coll_name = 'coll-1'
567613
@collection_manager.create_scope(scope_name)
614+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
615+
568616
@collection_manager.create_collection(
569617
Management::CollectionSpec.new do |spec|
570618
spec.name = coll_name
571619
spec.scope_name = scope_name
572620
end,
573621
Management::Options::Collection::CreateCollection.new(timeout: 80_000)
574622
)
623+
env.consistency.wait_until_collection_present(env.bucket, scope_name, coll_name)
575624

576625
refute_nil get_collection(scope_name, coll_name)
577626
end
@@ -580,12 +629,15 @@ def test_drop_collection_deprecated
580629
scope_name = get_scope_name
581630
coll_name = 'coll-1'
582631
@collection_manager.create_scope(scope_name)
632+
env.consistency.wait_until_scope_present(env.bucket, scope_name)
633+
583634
@collection_manager.create_collection(
584635
Management::CollectionSpec.new do |spec|
585636
spec.name = coll_name
586637
spec.scope_name = scope_name
587638
end
588639
)
640+
env.consistency.wait_until_collection_present(env.bucket, scope_name, coll_name)
589641

590642
refute_nil get_collection(scope_name, coll_name)
591643

@@ -596,6 +648,7 @@ def test_drop_collection_deprecated
596648
end,
597649
Management::Options::Collection::DropCollection.new(timeout: 80_000)
598650
)
651+
env.consistency.wait_until_collection_dropped(env.bucket, scope_name, coll_name)
599652

600653
assert_nil get_collection(scope_name, coll_name)
601654
end

test/collection_query_index_manager_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ def setup
3333
collection_mgr = @bucket.collections
3434
collection_mgr.create_scope(@scope_name)
3535

36+
env.consistency.wait_until_scope_present(env.bucket, @scope_name)
37+
3638
# Retry a few times in case the scope needs time to be created
3739
retry_for_duration(expected_errors: [Error::CouchbaseError]) do
3840
collection_mgr.create_collection(@scope_name, collection_name)
3941
end
4042

43+
env.consistency.wait_until_collection_present(env.bucket, @scope_name, collection_name)
44+
4145
@collection = @bucket.scope(@scope_name).collection(collection_name)
4246

4347
sleep(1)

test/query_index_manager_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def setup
2828
s.ram_quota_mb = 256
2929
end
3030
)
31+
env.consistency.wait_until_bucket_present(@bucket_name)
3132
retry_for_duration(expected_errors: [Error::BucketNotFound]) do
3233
@bucket = @cluster.bucket('query-idx-test-bucket')
3334
end

0 commit comments

Comments
 (0)