@@ -368,6 +368,23 @@ def test_diffsync_sync_from(backend_a, backend_b):
368368 backend_a .get_by_uids (["nyc" , "sfo" ], "device" )
369369
370370
371+ def check_successful_sync_log_sanity (log , src , dst , flags ):
372+ """Given a successful sync, make sure the captured structlogs are correct at a high level."""
373+ # All logs generated during the sync should include the src, dst, and flags data
374+ for event in log .events :
375+ assert "src" in event and event ["src" ] == src
376+ assert "dst" in event and event ["dst" ] == dst
377+ assert "flags" in event and event ["flags" ] == flags
378+
379+ # No warnings or errors should have been logged in a fully successful sync
380+ assert all (event ["level" ] == "debug" or event ["level" ] == "info" for event in log .events )
381+
382+ # Logs for beginning and end of diff and sync should have been generated
383+ assert log .has ("Beginning diff calculation" , level = "info" )
384+ assert log .has ("Diff calculation complete" , level = "info" )
385+ assert log .has ("Beginning sync" , level = "info" )
386+
387+
371388def check_sync_logs_against_diff (diffsync , diff , log , errors_permitted = False ):
372389 """Given a Diff, make sure the captured structlogs correctly correspond to its contents/actions."""
373390 for element in diff .get_children ():
@@ -441,29 +458,39 @@ def check_sync_logs_against_diff(diffsync, diff, log, errors_permitted=False):
441458 check_sync_logs_against_diff (diffsync , element .child_diff , log , errors_permitted )
442459
443460
444- def test_diffsync_sync_from_successful_logging (log , backend_a , backend_b ):
445- diff = backend_a .diff_from (backend_b )
461+ def test_diffsync_no_log_unchanged_by_default (log , backend_a ):
462+ backend_a .sync_from (backend_a )
463+
464+ # Make sure logs were accurately generated
465+ check_successful_sync_log_sanity (log , backend_a , backend_a , DiffSyncFlags .NONE )
466+
467+ # Since there were no changes, and we didn't set LOG_UNCHANGED_RECORDS, there should be no "unchanged" logs
468+ assert not any (event for event in log .events if "action" in event )
469+ assert not any (event for event in log .events if "status" in event )
470+
471+
472+ def test_diffsync_log_unchanged_even_if_no_changes_overall (log , backend_a ):
473+ diff = backend_a .diff_from (backend_a )
474+ assert not diff .has_diffs ()
446475 # Discard logs generated during diff calculation
447476 log .events = []
448477
449- backend_a .sync_from (backend_b , flags = DiffSyncFlags .LOG_UNCHANGED_RECORDS )
478+ backend_a .sync_from (backend_a , flags = DiffSyncFlags .LOG_UNCHANGED_RECORDS )
450479
451- # All logs generated during the sync should include the src, dst, and flags data
452- for event in log .events :
453- assert "src" in event and event ["src" ] == backend_b
454- assert "dst" in event and event ["dst" ] == backend_a
455- assert "flags" in event and event ["flags" ] == DiffSyncFlags .LOG_UNCHANGED_RECORDS
480+ # Make sure logs were accurately generated
481+ check_successful_sync_log_sanity (log , backend_a , backend_a , DiffSyncFlags .LOG_UNCHANGED_RECORDS )
482+ check_sync_logs_against_diff (backend_a , diff , log )
456483
457- # No warnings or errors should have been logged in a fully successful sync
458- assert all (event ["level" ] == "debug" or event ["level" ] == "info" for event in log .events )
459484
460- # Logs for beginning and end of diff and sync should have been generated
461- assert log .has ("Beginning diff calculation" , level = "info" )
462- assert log .has ("Diff calculation complete" , level = "info" )
463- assert log .has ("Beginning sync" , level = "info" )
464- assert log .has ("Sync complete" , level = "info" )
485+ def test_diffsync_sync_from_successful_logging (log , backend_a , backend_b ):
486+ diff = backend_a .diff_from (backend_b )
487+ # Discard logs generated during diff calculation
488+ log .events = []
489+
490+ backend_a .sync_from (backend_b , flags = DiffSyncFlags .LOG_UNCHANGED_RECORDS )
465491
466492 # Make sure logs were accurately generated
493+ check_successful_sync_log_sanity (log , backend_b , backend_a , DiffSyncFlags .LOG_UNCHANGED_RECORDS )
467494 check_sync_logs_against_diff (backend_a , diff , log )
468495
469496
0 commit comments