Skip to content

Commit 6b5e0f2

Browse files
author
Xin Dong
committed
- Enabled update tests in correctness;
- Modified MM to store documents in a dictionary who sorts the docs it holds by their _id field. It's doing its best to encode and sort the field in the same way with DocLayer and mongo; - Fixed a small bug in doclayer found by the correctness test (yay) that it throws wrong error;
1 parent 1a9b23b commit 6b5e0f2

3 files changed

Lines changed: 215 additions & 118 deletions

File tree

src/ExtOperator.actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ ACTOR static Future<Void> getValueAndMultiply(Reference<IReadWriteContext> cx,
413413
if (valueInDatabase.present()) {
414414
DataValue actualValue = valueInDatabase.get();
415415
if (actualValue.getSortType() != DVTypeCode::NUMBER)
416-
throw inc_applied_to_non_number();
416+
throw mul_applied_to_non_number();
417417
cx->set(path,
418418
doubleDispatchArithmetic(actualValue, valueToMultiply, [](LongDouble a, LongDouble b) { return a * b; })
419419
.encode_value());
@@ -608,7 +608,7 @@ ACTOR static Future<Void> doPullActor(Reference<IReadWriteContext> cx,
608608
std::set<DataValue> uniques) {
609609
state int length = wait(isArray(cx, path.toString()));
610610
if (length == -1)
611-
throw push_non_array();
611+
throw pull_non_array();
612612
else if (length == -2)
613613
return Void();
614614

test/correctness/document-correctness.py

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import os.path
2727
import random
2828
import sys
29+
import pprint
2930

3031
import pymongo
3132

@@ -151,6 +152,8 @@ def diff_results(cA, rA, cB, rB):
151152

152153

153154
def check_query(query, collection1, collection2, projection=None, sort=None, limit=0, skip=0):
155+
# if projection:
156+
# projection['_id'] = True
154157
util.trace('debug', '\n==================================================')
155158
util.trace('debug', 'query:', query)
156159
util.trace('debug', 'sort:', sort)
@@ -213,56 +216,59 @@ def check_query(query, collection1, collection2, projection=None, sort=None, lim
213216
return False
214217

215218

216-
def test_update(collections, verbose=False):
219+
def test_update(collection1, collection2, verbose=False):
217220
okay = True
218221
for i in range(1, 10):
219-
update = gen.random_update(collections[0])
222+
exceptionOne = None
223+
exceptionTwo = None
224+
update = gen.random_update(collection1)
220225

221226
util.trace('debug', '\n========== Update No.', i, '==========')
222227
util.trace('debug', 'Query:', update['query'])
223228
util.trace('debug', 'Update:', str(update['update']))
224229
util.trace('debug', 'Number results from collection: ', gen.count_query_results(
225-
collections[0], update['query']))
226-
for item in collections[0].find(update['query']):
230+
collection1, update['query']))
231+
for item in collection1.find(update['query']):
227232
util.trace('debug', 'Find Result0:', item)
228233

229-
exception = []
230-
exception_msg = []
231-
for coll in collections:
232-
try:
233-
if verbose:
234-
all = [x for x in coll.find(dict())]
235-
for item in coll.find(update['query']):
236-
print 'Before update doc:', item
237-
print 'Before update coll size: ', len(all)
238-
239-
coll.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
240-
241-
if verbose:
242-
all = [x for x in coll.find(dict())]
243-
for item in coll.find(update['query']):
244-
print 'After update doc:', item
245-
print 'After update coll size: ', len(all)
246-
247-
except pymongo.errors.OperationFailure as e:
248-
exception.append(e)
249-
exception_msg.append(
250-
util.join_n('Caught PyMongo error while attempting update: %s' % e[0],
251-
'Query: %s' % update['query'], 'Update: %s' % update['update'],
252-
'Upsert: {0}, Multi: {1}'.format(update['upsert'], update['multi'])))
253-
except MongoModelException as e:
254-
exception.append(e)
255-
exception_msg.append(
256-
util.join_n('Caught MongoModel error. Offending update(', str(update['query']),
257-
str(update['update']), str(update['upsert']), str(update['multi']), ')'))
258-
259-
if len(exception_msg) == 1:
260-
print 'Update: ' + str(update['update'])
261-
print '\033[91m', exception[0], '\033[0m'
262-
print '\033[91m', exception_msg[0], '\033[0m'
263-
return False
234+
try:
235+
if verbose:
236+
all = [x for x in collection1.find(dict())]
237+
for item in collection1.find(update['query']):
238+
print 'Before update doc:\n', pprint.pprint(item)
239+
print 'Before update collection1 size: ', len(all)
240+
collection1.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
241+
except pymongo.errors.OperationFailure as e:
242+
exceptionOne = e
243+
except MongoModelException as e:
244+
exceptionOne = e
245+
try:
246+
if verbose:
247+
all = [x for x in collection2.find(dict())]
248+
for item in collection2.find(update['query']):
249+
print 'Before update doc:\n', pprint.pprint(item)
250+
print 'Before update collection2 size: ', len(all)
251+
collection2.update(update['query'], update['update'], upsert=update['upsert'], multi=update['multi'])
252+
except pymongo.errors.OperationFailure as e:
253+
exceptionTwo = e
254+
except MongoModelException as e:
255+
exceptionTwo = e
256+
257+
if ((exceptionOne is None and exceptionTwo is None)
258+
or (exceptionOne is not None and exceptionTwo is not None)):
259+
# or (exceptionOne is not None and exceptionTwo is not None and exceptionOne.code == exceptionTwo.code)):
260+
# TODO re-enable the exact error check.
261+
pass
262+
else:
263+
print 'Unmatched result: '
264+
print type(exceptionOne), ': ', str(exceptionOne)
265+
print type(exceptionTwo), ': ', str(exceptionTwo)
266+
okay = False
267+
ignored_exception_check(exceptionOne)
268+
ignored_exception_check(exceptionTwo)
269+
return okay
264270

265-
if not check_query(dict(), collections[0], collections[1]):
271+
if not check_query(dict(), collection1, collection2):
266272
print 'Update: ' + str(update['update'])
267273
return False
268274

@@ -393,8 +399,9 @@ def _run_operation_(op1, op2):
393399
if not okay:
394400
return (okay, fname, None)
395401

396-
if update_tests_enabled:
397-
if not test_update([collection1, collection2], verbose):
402+
# if update_tests_enabled:
403+
if True:
404+
if not test_update(collection1, collection2, verbose):
398405
okay = False
399406
return (okay, fname, None)
400407

0 commit comments

Comments
 (0)