Skip to content

Commit efbbfb7

Browse files
committed
PYCBC-1697: Update collection/bucket mgmt tests that assume default engine is Couchstore
Motivation ========== In Morpheus the default storage engine is Magma, and some collection/bucket management tests that use the default bucket when they require a Couchstore bucket, are failing Changes ======= * Update history retention tests that verify that FeatureUnavailable is raised for Couchstore, to create a temporary Couchstore bucket. * Update the 'replica_index' bucket management tests to create a temporary Couchstore bucket. This is a views-related bucket parameter that's not available in Magma. Results ======= Tests pass Change-Id: I00b317433de082987cc78f37429227a0eb7ca234 Reviewed-on: https://review.couchbase.org/c/couchbase-python-client/+/231351 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Jared Casey <jared.casey@couchbase.com>
1 parent bf69cb1 commit efbbfb7

5 files changed

Lines changed: 92 additions & 54 deletions

File tree

acouchbase/tests/bucketmgmt_t.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ async def test_bucket_create_replica_index_true(self, cb_env, test_bucket):
117117
CreateBucketSettings(
118118
name=test_bucket,
119119
bucket_type=BucketType.COUCHBASE,
120+
storage_backend=StorageBackend.COUCHSTORE,
120121
ram_quota_mb=100,
121122
replica_index=True))
122123
bucket = await cb_env.try_n_times(10, 1, cb_env.bm.get_bucket, test_bucket)
@@ -130,6 +131,7 @@ async def test_bucket_create_replica_index_false(self, cb_env, test_bucket):
130131
CreateBucketSettings(
131132
name=test_bucket,
132133
bucket_type=BucketType.COUCHBASE,
134+
storage_backend=StorageBackend.COUCHSTORE,
133135
ram_quota_mb=100,
134136
replica_index=False))
135137
bucket = await cb_env.try_n_times(10, 1, cb_env.bm.get_bucket, test_bucket)

acouchbase/tests/collectionmgmt_t.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
import pytest_asyncio
2222

2323
from acouchbase.cluster import get_event_loop
24-
from couchbase.exceptions import (BucketDoesNotExistException,
25-
CollectionAlreadyExistsException,
24+
from couchbase.exceptions import (CollectionAlreadyExistsException,
2625
CollectionNotFoundException,
2726
DocumentNotFoundException,
2827
FeatureUnavailableException,
@@ -327,13 +326,12 @@ async def test_drop_collection_scope_not_found(self, cb_env):
327326
with pytest.raises(ScopeNotFoundException):
328327
await cb_env.test_bucket_cm.drop_collection("fake-scope", "fake-collection")
329328

330-
@pytest.mark.usefixtures('cleanup_collection')
331329
@pytest.mark.usefixtures('check_non_deduped_history_supported')
332330
@pytest.mark.asyncio
333331
async def test_create_collection_history_retention(self, cb_env):
334-
bucket_name = 'test-magma-bucket'
332+
bucket_name = f'test-bucket-{str(uuid4())[:6]}'
335333
scope_name = '_default'
336-
collection_name = self.TEST_COLLECTION
334+
collection_name = 'test-collection'
337335

338336
await cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA)
339337
bucket = cb_env.cluster.bucket(bucket_name)
@@ -350,36 +348,38 @@ async def test_create_collection_history_retention(self, cb_env):
350348
assert collection_spec is not None
351349
assert collection_spec.history
352350

353-
await cb_env.try_n_times_till_exception(10,
354-
3,
355-
cb_env.bm.drop_bucket,
356-
bucket_name,
357-
expected_exceptions=(BucketDoesNotExistException,))
351+
await cb_env.purge_buckets([bucket_name])
358352

359-
@pytest.mark.usefixtures('cleanup_collection')
360353
@pytest.mark.usefixtures('check_non_deduped_history_supported')
361354
@pytest.mark.asyncio
362355
async def test_create_collection_history_retention_unsupported(self, cb_env):
356+
bucket_name = f'test-bucket-{str(uuid4())[:6]}'
363357
scope_name = '_default'
364-
collection_name = self.TEST_COLLECTION
358+
collection_name = 'test-collection'
359+
360+
await cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE)
361+
bucket = cb_env.cluster.bucket(bucket_name)
362+
await cb_env.try_n_times(10, 1, bucket.on_connect)
363+
cm = bucket.collections()
365364

366365
# Couchstore does not support history retention
367366
with pytest.raises(FeatureUnavailableException):
368-
await cb_env.test_bucket_cm.create_collection(
367+
await cm.create_collection(
369368
scope_name, collection_name, CreateCollectionSettings(history=True))
370369

371370
with pytest.raises(FeatureUnavailableException):
372-
await cb_env.test_bucket_cm.create_collection(
371+
await cm.create_collection(
373372
scope_name, collection_name, CreateCollectionSettings(history=False))
374373

375-
@pytest.mark.usefixtures('cleanup_collection')
374+
await cb_env.purge_buckets([bucket_name])
375+
376376
@pytest.mark.usefixtures('check_non_deduped_history_supported')
377377
@pytest.mark.usefixtures('check_update_collection_supported')
378378
@pytest.mark.asyncio
379379
async def test_update_collection_history_retention(self, cb_env):
380-
bucket_name = 'test-magma-bucket'
380+
bucket_name = f'test-bucket-{str(uuid4())[:6]}'
381381
scope_name = '_default'
382-
collection_name = self.TEST_COLLECTION
382+
collection_name = 'test-collection'
383383

384384
await cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA)
385385
bucket = cb_env.cluster.bucket(bucket_name)
@@ -406,35 +406,39 @@ async def test_update_collection_history_retention(self, cb_env):
406406
assert collection_spec is not None
407407
assert collection_spec.history
408408

409-
await cb_env.try_n_times_till_exception(10,
410-
3,
411-
cb_env.bm.drop_bucket,
412-
bucket_name,
413-
expected_exceptions=(BucketDoesNotExistException,))
409+
await cb_env.purge_buckets([bucket_name])
414410

415411
@pytest.mark.usefixtures("cleanup_collection")
416412
@pytest.mark.usefixtures('check_non_deduped_history_supported')
417413
@pytest.mark.usefixtures('check_update_collection_supported')
418414
@pytest.mark.asyncio
419415
async def test_update_collection_history_retention_unsupported(self, cb_env):
416+
bucket_name = f'test-bucket-{str(uuid4())[:6]}'
420417
scope_name = '_default'
421-
collection_name = self.TEST_COLLECTION
418+
collection_name = 'test-collection'
422419

423-
await cb_env.test_bucket_cm.create_collection(scope_name, collection_name)
424-
collection_spec = await cb_env.get_collection(scope_name, collection_name)
420+
await cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE)
421+
bucket = cb_env.cluster.bucket(bucket_name)
422+
await cb_env.try_n_times(10, 1, bucket.on_connect)
423+
cm = bucket.collections()
424+
425+
await cm.create_collection(scope_name, collection_name)
426+
collection_spec = await cb_env.get_collection(scope_name, collection_name, bucket_name)
425427
assert collection_spec is not None
426428
assert collection_spec.history is False
427429

428430
# Couchstore does not support history retention
429431
with pytest.raises(FeatureUnavailableException):
430-
await cb_env.test_bucket_cm.update_collection(
432+
await cm.update_collection(
431433
scope_name, collection_name, UpdateCollectionSettings(history=True))
432434

433435
# Collection history retention setting remains unchanged
434-
collection_spec = await cb_env.get_collection(scope_name, collection_name)
436+
collection_spec = await cb_env.get_collection(scope_name, collection_name, bucket_name)
435437
assert collection_spec is not None
436438
assert collection_spec.history is False
437439

440+
await cb_env.purge_buckets([bucket_name])
441+
438442
@pytest.mark.usefixtures('cleanup_collection')
439443
@pytest.mark.usefixtures('check_update_collection_supported')
440444
@pytest.mark.usefixtures('check_update_collection_max_expiry_supported')

couchbase/tests/bucketmgmt_t.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def test_bucket_create_replica_index_false(self, cb_env):
209209
CreateBucketSettings(
210210
name=bucket_name,
211211
bucket_type=BucketType.COUCHBASE,
212+
storage_backend=StorageBackend.COUCHSTORE, # Views only supported on CouchStore
212213
ram_quota_mb=100,
213214
replica_index=False))
214215
cb_env.consistency.wait_until_bucket_present(bucket_name)
@@ -223,6 +224,7 @@ def test_bucket_create_replica_index_true(self, cb_env):
223224
CreateBucketSettings(
224225
name=bucket_name,
225226
bucket_type=BucketType.COUCHBASE,
227+
storage_backend=StorageBackend.COUCHSTORE, # Views only supported on CouchStore
226228
ram_quota_mb=100,
227229
replica_index=True))
228230
cb_env.consistency.wait_until_bucket_present(bucket_name)

couchbase/tests/collectionmgmt_t.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818
import pytest
1919

20-
from couchbase.exceptions import (BucketDoesNotExistException,
21-
CollectionAlreadyExistsException,
20+
from couchbase.exceptions import (CollectionAlreadyExistsException,
2221
CollectionNotFoundException,
2322
DocumentNotFoundException,
2423
FeatureUnavailableException,
@@ -95,6 +94,11 @@ def check_negative_collection_max_expiry_supported(self, cb_env):
9594
cb_env.server_version_short,
9695
cb_env.mock_server_type)
9796

97+
@pytest.fixture()
98+
def drop_bucket(self, cb_env):
99+
yield
100+
cb_env.drop_bucket()
101+
98102
def test_collection_goes_in_correct_bucket(self, cb_env):
99103
collection_name = cb_env.get_collection_name()
100104
scope_name = '_default'
@@ -287,89 +291,95 @@ def test_get_all_scopes(self, cb_env):
287291
assert c.history is None or isinstance(c.history, bool)
288292

289293
@pytest.mark.usefixtures('check_non_deduped_history_supported')
294+
@pytest.mark.usefixtures('drop_bucket')
290295
def test_create_collection_history_retention(self, cb_env):
291-
bucket_name = 'test-magma-bucket'
296+
bucket_name = cb_env.get_bucket_name()
292297
scope_name = '_default'
293-
collection_name = cb_env.get_collection_name()
298+
collection_name = 'test-collection'
294299

295300
cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA)
296301
bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name)
297302
cm = bucket.collections()
298303

299304
cm.create_collection(scope_name, collection_name, CreateCollectionSettings(history=True))
300305
cb_env.consistency.wait_until_collection_present(bucket.name, scope_name, collection_name)
306+
301307
collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name)
302308
assert collection_spec is not None
303309
assert collection_spec.history
304310

305-
TestEnvironment.try_n_times_till_exception(10,
306-
3,
307-
cb_env.bm.drop_bucket,
308-
bucket_name,
309-
expected_exceptions=(BucketDoesNotExistException,))
310-
311311
@pytest.mark.usefixtures('check_non_deduped_history_supported')
312+
@pytest.mark.usefixtures('drop_bucket')
312313
def test_create_collection_history_retention_unsupported(self, cb_env):
314+
bucket_name = cb_env.get_bucket_name()
313315
scope_name = '_default'
314-
collection_name = cb_env.get_collection_name()
316+
collection_name = 'test-collection'
317+
318+
cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE)
319+
bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name)
320+
cm = bucket.collections()
315321

316322
# Couchstore does not support history retention
317323
with pytest.raises(FeatureUnavailableException):
318-
cb_env.test_bucket_cm.create_collection(
324+
cm.create_collection(
319325
scope_name, collection_name, CreateCollectionSettings(history=True))
320326

321327
with pytest.raises(FeatureUnavailableException):
322-
cb_env.test_bucket_cm.create_collection(
328+
cm.create_collection(
323329
scope_name, collection_name, CreateCollectionSettings(history=False))
324330

325331
@pytest.mark.usefixtures('check_non_deduped_history_supported')
326332
@pytest.mark.usefixtures('check_update_collection_supported')
333+
@pytest.mark.usefixtures('drop_bucket')
327334
def test_update_collection_history_retention(self, cb_env):
328-
bucket_name = 'test-magma-bucket'
335+
bucket_name = cb_env.get_bucket_name()
329336
scope_name = '_default'
330-
collection_name = cb_env.get_collection_name()
337+
collection_name = 'test-collection'
331338

332339
cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA)
333340
bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name)
334341
cm = bucket.collections()
335342

336343
cm.create_collection(scope_name, collection_name, CreateCollectionSettings(history=False))
337344
cb_env.consistency.wait_until_collection_present(bucket.name, scope_name, collection_name)
345+
338346
collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name)
339347
assert collection_spec is not None
340348
assert not collection_spec.history
341349

342350
cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True))
343351
cb_env.consistency.wait_until_collection_has_settings(
344352
bucket.name, scope_name, collection_name, {'history': True})
353+
345354
collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name)
346355
assert collection_spec is not None
347356
assert collection_spec.history
348357

349-
TestEnvironment.try_n_times_till_exception(10,
350-
3,
351-
cb_env.bm.drop_bucket,
352-
bucket_name,
353-
expected_exceptions=(BucketDoesNotExistException,))
354-
355358
@pytest.mark.usefixtures('check_non_deduped_history_supported')
356359
@pytest.mark.usefixtures('check_update_collection_supported')
360+
@pytest.mark.usefixtures('drop_bucket')
357361
def test_update_collection_history_retention_unsupported(self, cb_env):
362+
bucket_name = cb_env.get_bucket_name()
358363
scope_name = '_default'
359-
collection_name = cb_env.get_collection_name()
364+
collection_name = 'test-collection'
360365

361-
cb_env.test_bucket_cm.create_collection(scope_name, collection_name)
362-
cb_env.consistency.wait_until_collection_present(cb_env.test_bucket.name, scope_name, collection_name)
363-
collection_spec = cb_env.get_collection(scope_name, collection_name)
366+
cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE)
367+
bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name)
368+
cm = bucket.collections()
369+
370+
cm.create_collection(scope_name, collection_name)
371+
cb_env.consistency.wait_until_collection_present(bucket_name, scope_name, collection_name)
372+
373+
collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name)
364374
assert collection_spec is not None
365375
assert collection_spec.history is False
366376

367377
# Couchstore does not support history retention
368378
with pytest.raises(FeatureUnavailableException):
369-
cb_env.test_bucket_cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True))
379+
cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True))
370380

371381
# Collection history retention setting remains unchanged
372-
collection_spec = cb_env.get_collection(scope_name, collection_name)
382+
collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name)
373383
assert collection_spec is not None
374384
assert collection_spec.history is False
375385

tests/environments/collection_mgmt_environment.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,23 @@ def get_scope_names(self):
5252
available_ids = self._used_scope_ids.difference(self._dropped_scope_ids)
5353
return list(available_ids)
5454

55+
def drop_bucket(self):
56+
available_ids = self._used_bucket_ids.difference(self._dropped_bucket_ids)
57+
bucket_name = available_ids.pop()
58+
self._dropped_bucket_ids.add(bucket_name)
59+
try:
60+
self.bm.drop_bucket(bucket_name)
61+
except BucketDoesNotExistException:
62+
pass
63+
self.consistency.wait_until_bucket_dropped(bucket_name)
64+
65+
def get_bucket_name(self):
66+
all_ids = set(self._bucket_ids)
67+
available_ids = all_ids.difference(self._used_bucket_ids)
68+
bucket_id = random.choice(list(available_ids))
69+
self._used_bucket_ids.add(bucket_id)
70+
return bucket_id
71+
5572
def setup(self):
5673
TestEnvironment.try_n_times(3, 5, self.setup_collection_mgmt, self.TEST_BUCKET)
5774
self._batch_id = str(uuid.uuid4())[:8]
@@ -61,6 +78,9 @@ def setup(self):
6178
self._used_collection_ids = set()
6279
self._dropped_collection_ids = set()
6380
self._collection_ids = [f'{self._batch_id}_collection_{i}' for i in range(50)]
81+
self._bucket_ids = [f'{self._batch_id}_bucket_{i}' for i in range(10)]
82+
self._used_bucket_ids = set()
83+
self._dropped_bucket_ids = set()
6484

6585
def teardown(self):
6686
for c in self._used_collection_ids:

0 commit comments

Comments
 (0)