MCPcopy Create free account
hub / github.com/dnote/dnote / TestSync_ConvergeSameBookNames

Function TestSync_ConvergeSameBookNames

pkg/e2e/sync/basic_test.go:3717–3811  ·  view source on GitHub ↗

TestSync_ConvergeSameBookNames tests that two clients don't enter an infinite sync loop if they try to sync books with the same names. Books shouldn't get marked dirty when re-downloaded from server.

(t *testing.T)

Source from the content-addressed store, hash-verified

3715// TestSync_ConvergeSameBookNames tests that two clients don't enter an infinite sync loop if they
3716// try to sync books with the same names. Books shouldn't get marked dirty when re-downloaded from server.
3717func TestSync_ConvergeSameBookNames(t *testing.T) {
3718 env := setupTestEnv(t)
3719 tmpDir := t.TempDir()
3720
3721 // Setup two separate client databases
3722 client1DB := fmt.Sprintf("%s/client1.db", tmpDir)
3723 client2DB := fmt.Sprintf("%s/client2.db", tmpDir)
3724 defer os.Remove(client1DB)
3725 defer os.Remove(client2DB)
3726
3727 // Set up sessions
3728 user := setupUser(t, env)
3729 db1 := testutils.MustOpenDatabase(t, client1DB)
3730 db2 := testutils.MustOpenDatabase(t, client2DB)
3731 defer db1.Close()
3732 defer db2.Close()
3733
3734 // Client 1: First sync to empty server
3735 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client1DB, "add", "testbook", "-c", "client1 note1")
3736 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client1DB, "add", "anotherbook", "-c", "client1 note2")
3737 login(t, db1, env.ServerDB, user)
3738 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client1DB, "sync")
3739 checkState(t, db1, user, env.ServerDB, systemState{
3740 clientNoteCount: 2,
3741 clientBookCount: 2,
3742 clientLastMaxUSN: 4,
3743 clientLastSyncAt: serverTime.Unix(),
3744 serverNoteCount: 2,
3745 serverBookCount: 2,
3746 serverUserMaxUSN: 4,
3747 })
3748
3749 // Client 2: Sync (downloads client 1's data, adds own notes) =====
3750 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client2DB, "add", "testbook", "-c", "client2 note1")
3751 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client2DB, "add", "anotherbook", "-c", "client2 note2")
3752 login(t, db2, env.ServerDB, user)
3753 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client2DB, "sync")
3754 // Verify state after client2 sync
3755 checkState(t, db2, user, env.ServerDB, systemState{
3756 clientNoteCount: 4,
3757 clientBookCount: 2,
3758 clientLastMaxUSN: 8,
3759 clientLastSyncAt: serverTime.Unix(),
3760 serverNoteCount: 4,
3761 serverBookCount: 2,
3762 serverUserMaxUSN: 8,
3763 })
3764
3765 // Client 1: Sync again. It downloads client2's changes (2 extra notes).
3766 clitest.RunDnoteCmd(t, env.CmdOpts, cliBinaryName, "--dbPath", client1DB, "sync")
3767
3768 // Verify MaxUSN did not increase (client1 should only download, not upload)
3769 // Client1 still has: 2 original books + 4 notes (2 own + 2 from client2)
3770 checkState(t, db1, user, env.ServerDB, systemState{
3771 clientNoteCount: 4,
3772 clientBookCount: 2,
3773 clientLastMaxUSN: 8,
3774 clientLastSyncAt: serverTime.Unix(),

Callers

nothing calls this directly

Calls 5

setupUserFunction · 0.85
loginFunction · 0.85
checkStateFunction · 0.85
setupTestEnvFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected