Exemplo n.º 1
0
func TestFigure3C(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 b
	b.ResolveOurs(&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.Conflict; 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 */ })
}