func TestFigure8(t *testing.T) { a := clock.Create(10, 1) a.UpdateSync(10, 2) b := &clock.Clock{} b.ResolveTheirs(a) // Figure 8 does not contain the compressed modtime optimization. b.UpdateParent(11, 4) c := &clock.Clock{} if g, e := clock.Sync(b, c), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } c.ResolveTheirs(b) c.UpdateSync(12, 5) if g, e := c.String(), `{sync{10:2 11:4 12:5} mod{10:1 11:4} create{10:1}}`; g != e { t.Errorf("bad state C: %v != %v", g, e) } a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) c.ValidateFile(&clock.Clock{ /* dummy parent */ }) }
func TestFigure2C(t *testing.T) { var b clock.Clock a := clock.Create(10, 1) if g, e := clock.Sync(a, &b), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } b.ResolveTheirs(a) a.Update(10, 3) b.Update(11, 3) if g, e := clock.Sync(&b, a), clock.Conflict; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } if g, e := a.String(), `{sync{10:3} mod{10:3} create{10:1}}`; g != e { t.Errorf("bad state A: %v != %v", g, e) } if g, e := b.String(), `{sync{10:1 11:3} mod{11:3} create{10:1}}`; g != e { t.Errorf("bad state B: %v != %v", g, e) } a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) }
func TestFigure5A(t *testing.T) { a := clock.Create(10, 1) a.Update(10, 2) // delete b := &clock.Clock{} if g, e := clock.Sync(a, b), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } b.ResolveTheirs(a) b = clock.Create(11, 4) if g, e := clock.SyncToMissing(b, a), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.ResolveTheirs(b) a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) }
func TestFigure3B(t *testing.T) { var a clock.Clock var b clock.Clock var c clock.Clock b.Update(11, 1) if g, e := clock.Sync(&b, &a), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.ResolveTheirs(&b) if g, e := clock.Sync(&b, &c), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } c.ResolveTheirs(&b) a.Update(10, 3) b.Update(11, 3) if g, e := clock.Sync(&a, &b), clock.Conflict; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } // resolve conflict in favor of a b.ResolveTheirs(&a) if g, e := clock.Sync(&a, &b), clock.Nothing; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } if g, e := clock.Sync(&c, &b), clock.Nothing; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.Update(10, 6) if g, e := clock.Sync(&a, &b), clock.Copy; g != e { t.Errorf("bad sync decision: %v is to %v -> %v != %v", a, b, g, e) } a.ValidateFile(&clock.Clock{ /* dummy parent */ }) b.ValidateFile(&clock.Clock{ /* dummy parent */ }) c.ValidateFile(&clock.Clock{ /* dummy parent */ }) }