@@ -1251,7 +1251,7 @@ def test_replica_number(self):
12511251 # refresh object
12521252 obj = session .data_objects .get (obj_path )
12531253
1254- # assertions on replicas
1254+ # assertions on replicas
12551255 self .assertEqual (len (obj .replicas ), number_of_replicas )
12561256 self .assertEqual (
12571257 {repl .number for repl in obj .replicas },
@@ -2992,6 +2992,35 @@ def test_handling_of_termination_signals_during_multithread_put__issue_722(self)
29922992
29932993 test_put__issue_722 (self )
29942994
2995+ def test_default_sorting_of_replicas__issue_647 (self ):
2996+ basename = unique_name (my_function_name (), datetime .now ()) + '_dataobj_647'
2997+ with self .create_simple_resc () as newResc1 , self .create_simple_resc () as newResc2 :
2998+ data = helpers .make_object (self .sess , f'{ helpers .home_collection (self .sess )} /{ basename } ' )
2999+
3000+ # Precondition for an eventual total of 3 replicas: initial data replica is not on either of the new resources.
3001+ self .assertFalse ({repl .resource_name for repl in data .replicas } & {newResc1 , newResc2 })
3002+ try :
3003+ data .replicate (resource = newResc1 )
3004+
3005+ # Ensure that one of the replicas is stale, to test proper sorting.
3006+ with data .open ('a' ,** {kw .RESC_NAME_KW :newResc1 }) as f :
3007+ f .write (b'.' )
3008+ time .sleep (2 )
3009+
3010+ # Voting should ensure exactly two good replicas of the three.
3011+ data .replicate (resource = newResc2 )
3012+
3013+ # refresh replicas
3014+ data = self .sess .data_objects .get (data .path )
3015+
3016+ # Test replica sorting.
3017+ self .assertEqual (data .replicas [0 ].status , '1' )
3018+ self .assertEqual (data .replicas [0 ].modify_time , data .modify_time )
3019+ self .assertGreater (data .replicas [0 ].modify_time , data .replicas [1 ].modify_time )
3020+ finally :
3021+ if data :
3022+ data .unlink (force = True )
3023+
29953024
29963025if __name__ == "__main__" :
29973026 # let the tests find the parent irods lib
0 commit comments