Handle nested child syncs (#2220)

This commit is contained in:
Zach Gollwitzer
2025-05-07 18:12:08 -04:00
committed by GitHub
parent 8b857e9c8a
commit 2707a40a2a
3 changed files with 29 additions and 15 deletions

View File

@@ -32,29 +32,43 @@ class SyncTest < ActiveSupport::TestCase
assert_equal "test sync error", @sync.error
end
# Order is important here. Parent syncs must implement sync_data so that their own work
# is 100% complete *prior* to queueing up child syncs.
test "runs sync with child syncs" do
family = families(:dylan_family)
parent = Sync.create!(syncable: family)
child1 = Sync.create!(syncable: family.accounts.first, parent: parent)
child2 = Sync.create!(syncable: family.accounts.last, parent: parent)
child2 = Sync.create!(syncable: family.accounts.second, parent: parent)
grandchild = Sync.create!(syncable: family.accounts.last, parent: child2)
parent.syncable.expects(:sync_data).returns([]).once
child1.syncable.expects(:sync_data).returns([]).once
child2.syncable.expects(:sync_data).returns([]).once
grandchild.syncable.expects(:sync_data).returns([]).once
parent.perform # no-op
assert_equal "syncing", parent.status
assert_equal "pending", parent.status
assert_equal "pending", child1.status
assert_equal "pending", child2.status
assert_equal "pending", grandchild.status
parent.perform
assert_equal "syncing", parent.reload.status
child1.perform
assert_equal "completed", child1.status
assert_equal "syncing", parent.status
assert_equal "completed", child1.reload.status
assert_equal "syncing", parent.reload.status
child2.perform
assert_equal "completed", child2.status
assert_equal "completed", parent.status
assert_equal "syncing", child2.reload.status
assert_equal "completed", child1.reload.status
assert_equal "syncing", parent.reload.status
# Will complete the parent and grandparent syncs
grandchild.perform
assert_equal "completed", grandchild.reload.status
assert_equal "completed", child1.reload.status
assert_equal "completed", child2.reload.status
assert_equal "completed", parent.reload.status
end
end