3434import util
3535from mongo_model import MongoCollection
3636from mongo_model import MongoModel
37+ from mongo_model import SortedDict
38+ from gen import HashableOrderedDict
3739from util import MongoModelException
3840
3941
@@ -152,9 +154,8 @@ def diff_results(cA, rA, cB, rB):
152154
153155
154156def 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
219220def 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
278285class 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 ):
0 commit comments