Skip to content

Commit 9b001f1

Browse files
author
Xin Dong
committed
Fine-tune the unique index generating likelyhood
1 parent 2709f6f commit 9b001f1

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

test/correctness/document-correctness.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,31 @@ def _run_operation_(op1, op2):
333333
transactional_shim.remove(collection2)
334334

335335
indexes = []
336+
num_of_indexes = 5;
336337
indexes_first = gen.global_prng.choice([True, False])
337338
if indexes_enabled:
338-
for i in range(0, 5):
339+
for i in range(0, num_of_indexes):
339340
index_obj = gen.random_index_spec()
340341
indexes.append(index_obj)
341342

343+
# 0.5% likelyhood to allow using unique index in this iteration, assuming a uniform distribution
344+
useUnique = (gen.global_prng.randint(1,200) == 1)
345+
# only allow one out of $num_of_indexes to be unique.
346+
allowed_ii = gen.global_prng.randint(1,num_of_indexes)
342347
if indexes_first:
348+
ii = 1
343349
for i in indexes:
344-
# 5% likelyhood to be unique, assuming a uniform distribution
345-
uniqueIndex = (gen.global_prng.randint(1,20) == 1)
350+
if ii == allowed_ii:
351+
uniqueIndex = useUnique
352+
else:
353+
uniqueIndex = False
346354
okay = _run_operation_(
347355
(transactional_shim.ensure_index, (collection1, i), {"unique":uniqueIndex}),
348356
(transactional_shim.ensure_index, (collection2, i), {"unique":uniqueIndex})
349357
)
350358
if not okay:
351359
return (okay, fname, None)
360+
ii += 1
352361
docs = []
353362
for i in range(0, num_doc):
354363
doc = gen.random_document(True)
@@ -363,16 +372,20 @@ def _run_operation_(op1, op2):
363372
return (okay, fname, None)
364373

365374
if not indexes_first:
375+
ii = 1
366376
for i in indexes:
367-
# 5% likelyhood to be unique, assuming a uniform distribution
368-
uniqueIndex = (gen.global_prng.randint(1,20) == 1)
377+
if ii == allowed_ii:
378+
uniqueIndex = useUnique
379+
else:
380+
uniqueIndex = False
369381
okay = _run_operation_(
370382
(transactional_shim.ensure_index, (collection1, i), {"unique":uniqueIndex}),
371383
(transactional_shim.ensure_index, (collection2, i), {"unique":uniqueIndex})
372384
)
373385
if not okay:
374386
print "Failed when adding index after insert"
375387
return (okay, fname, None)
388+
ii += 1
376389

377390
okay = check_query(dict(), collection1, collection2)
378391
if not okay:

0 commit comments

Comments
 (0)