Skip to content

Commit 0ece69e

Browse files
author
Xin Dong
committed
Do not allow None value generated. Enabled Update tests
1 parent 6117bae commit 0ece69e

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

test/correctness/document-correctness.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import util
3535
from mongo_model import MongoCollection
3636
from mongo_model import MongoModel
37+
from mongo_model import SortedDict
38+
from gen import HashableOrderedDict
3739
from util import MongoModelException
3840

3941

@@ -152,9 +154,8 @@ def diff_results(cA, rA, cB, rB):
152154

153155

154156
def check_query(query, collection1, collection2, projection=None, sort=None, limit=0, skip=0):
155-
# if projection:
156-
# projection['_id'] = True
157157
util.trace('debug', '\n==================================================')
158+
util.trace('debug', 'checking consistency bettwen the two collections...')
158159
util.trace('debug', 'query:', query)
159160
util.trace('debug', 'sort:', sort)
160161
util.trace('debug', 'limit:', limit)
@@ -218,24 +219,27 @@ def check_query(query, collection1, collection2, projection=None, sort=None, lim
218219

219220
def test_update(collection1, collection2, verbose=False):
220221
okay = True
222+
skip_current_iteration = False
221223
for i in range(1, 10):
222224
exceptionOne = None
223225
exceptionTwo = None
224226
update = gen.random_update(collection1)
225227

226-
util.trace('debug', '\n========== Update No.', i, '==========')
227-
util.trace('debug', 'Query:', update['query'])
228-
util.trace('debug', 'Update:', str(update['update']))
229-
util.trace('debug', 'Number results from collection: ', gen.count_query_results(
228+
util.trace('error', '\n========== Update No.', i, '==========')
229+
util.trace('error', 'Query:', update['query'])
230+
util.trace('error', 'Update:', str(update['update']))
231+
util.trace('error', 'Number results from collection: ', gen.count_query_results(
230232
collection1, update['query']))
231233
for item in collection1.find(update['query']):
232-
util.trace('debug', 'Find Result0:', item)
234+
util.trace('error', 'Find Result1:', item)
235+
for item in collection2.find(update['query']):
236+
util.trace('error', 'Find Result2:', item)
233237

234238
try:
235239
if verbose:
236240
all = [x for x in collection1.find(dict())]
237241
for item in collection1.find(update['query']):
238-
print 'Before update doc:\n', pprint.pprint(item)
242+
print '[{}] Before update doc:{}'.format(type(collection1), item)
239243
print 'Before update collection1 size: ', len(all)
240244
collection1.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
241245
except pymongo.errors.OperationFailure as e:
@@ -246,33 +250,36 @@ def test_update(collection1, collection2, verbose=False):
246250
if verbose:
247251
all = [x for x in collection2.find(dict())]
248252
for item in collection2.find(update['query']):
249-
print 'Before update doc:\n', pprint.pprint(item)
253+
print '[{}]Before update doc:{}'.format(type(collection2), item)
250254
print 'Before update collection2 size: ', len(all)
251255
collection2.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
252256
except pymongo.errors.OperationFailure as e:
253257
exceptionTwo = e
254258
except MongoModelException as e:
255259
exceptionTwo = e
256260

257-
if ((exceptionOne is None and exceptionTwo is None)
258-
or (exceptionOne is not None and exceptionTwo is not None)):
261+
if (exceptionOne is None and exceptionTwo is None):
262+
# happy case, proceed to consistency check
263+
pass
264+
elif exceptionOne is not None and exceptionTwo is not None:
259265
# or (exceptionOne is not None and exceptionTwo is not None and exceptionOne.code == exceptionTwo.code)):
260266
# TODO re-enable the exact error check.
261-
pass
267+
# TODO re-enable consistency check when failure happened
268+
skip_current_iteration = True
269+
return (True, skip_current_iteration)
262270
else:
263271
print 'Unmatched result: '
264272
print type(exceptionOne), ': ', str(exceptionOne)
265273
print type(exceptionTwo), ': ', str(exceptionTwo)
266274
okay = False
267275
ignored_exception_check(exceptionOne)
268276
ignored_exception_check(exceptionTwo)
269-
return okay
277+
return (okay, skip_current_iteration)
270278

271279
if not check_query(dict(), collection1, collection2):
272-
print 'Update: ' + str(update['update'])
273-
return False
280+
return (False, skip_current_iteration)
274281

275-
return okay
282+
return (okay, skip_current_iteration)
276283

277284

278285
class IgnoredException(Exception):
@@ -399,10 +406,13 @@ def _run_operation_(op1, op2):
399406
if not okay:
400407
return (okay, fname, None)
401408

402-
# if update_tests_enabled:
403-
if True:
404-
if not test_update(collection1, collection2, verbose):
405-
okay = False
409+
if update_tests_enabled:
410+
okay, skip_current_iteration = test_update(collection1, collection2, verbose)
411+
if skip_current_iteration:
412+
if verbose:
413+
print "Skipping current iteration due to the failure from update."
414+
return (True, fname, None)
415+
if not okay:
406416
return (okay, fname, None)
407417

408418
for ii in range(1, 30):

test/correctness/gen.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,10 @@ def random_id_value():
183183
def random_value():
184184
r = global_prng.random()
185185
while True:
186-
if (r < 0.1) and generator_options.test_nulls:
187-
val = None
188-
elif (r < 0.2):
186+
# TODO re-enable None value generating
187+
# if (r < 0.1) and generator_options.test_nulls:
188+
# val = None
189+
if (r < 0.2):
189190
val = random_float()
190191
elif (r < 0.4):
191192
val = random_string(global_prng.randint(1, 8))

0 commit comments

Comments
 (0)