Refactor and increase robustness of mutual anchor tests

This commit is contained in:
Tracy Rust 2024-04-02 13:15:37 -04:00
parent 42707b3589
commit 820b982f23
1 changed files with 56 additions and 45 deletions

View File

@ -570,48 +570,7 @@ test("Record digestion is order independent", () => {
*/
describe("records anchored to each other and future timestamp resolves", () => {
let prop;
let reca;
let recb;
beforeEach(() => {
prop = constructActiveProperty("machine1", "bananas");
//So the hallmark here is that they both are aware of each other... Which shouldn't be possible
// and a brief look above I didn't see a case testing it (but it's late and I'm tired so maybe I missed it)
// either way this got through and caused an inconsistent sync in Binder so I'm enshrining it.
reca = createRecord(prop, "delete", null);
reca.timestamp = 1;
reca.machineId = "a";
reca.machineIndex = 1;
reca.anchors = {"b": 1};
recb = createRecord(prop, "write", true);
recb.timestamp = 2; //still fails if same...
recb.machineId = "b";
recb.machineIndex = 1;
recb.anchors = {"a": 1};
});
test("B before A, and the property is alive", () => {
digestRecordIntoProperty(prop, recb);
digestRecordIntoProperty(prop, reca);
expect(readPropertyValue(prop)).toBe(true);
});
test("A before B, and the property is alive", () => {
digestRecordIntoProperty(prop, reca);
digestRecordIntoProperty(prop, recb);
expect(readPropertyValue(prop)).toBe(true);
});
});
describe("records anchored to each other, same timestamps", () => {
describe("records anchored to each other", () => {
let prop;
let reca;
let recb;
@ -636,19 +595,71 @@ describe("records anchored to each other, same timestamps", () => {
recb.anchors = {"a": 1};
});
//Write takes precedence over delete when all else is in conflict.
test("B before A, and the property is alive", () => {
test("B before A, same timestamp, write supersedes", () => {
digestRecordIntoProperty(prop, recb);
digestRecordIntoProperty(prop, reca);
expect(readPropertyValue(prop)).toBe(true);
});
test("A before B, and the property is alive", () => {
test("A before B, same timestamp, write supersedes", () => {
digestRecordIntoProperty(prop, reca);
digestRecordIntoProperty(prop, recb);
expect(readPropertyValue(prop)).toBe(true);
});
test("B before A, future write, write supersedes", () => {
recb.timestamp = 2;
digestRecordIntoProperty(prop, recb);
digestRecordIntoProperty(prop, reca);
expect(readPropertyValue(prop)).toBe(true);
});
test("A before B, future write, write supersedes", () => {
recb.timestamp = 2;
digestRecordIntoProperty(prop, reca);
digestRecordIntoProperty(prop, recb);
expect(readPropertyValue(prop)).toBe(true);
});
test("B before A, future delete, delete supersedes", () => {
reca.timestamp = 2;
digestRecordIntoProperty(prop, recb);
digestRecordIntoProperty(prop, reca);
expect(readPropertyValue(prop)).toBe(undefined);
});
test("A before B, future delete, delete supersedes", () => {
reca.timestamp = 2;
digestRecordIntoProperty(prop, reca);
digestRecordIntoProperty(prop, recb);
expect(readPropertyValue(prop)).toBe(undefined);
});
test("B before A, same timestamp, conflicting write, lexicographically higher machine wins", () => {
reca.recordType = "write";
reca.value = "69";
recb.value = "42";
digestRecordIntoProperty(prop, recb);
digestRecordIntoProperty(prop, reca);
expect(readPropertyValue(prop)).toBe(42);
});
test("A before B, same timestamp, conflicting write, lexicographically higher machine wins", () => {
reca.recordType = "write";
reca.value = "69";
recb.value = "42";
digestRecordIntoProperty(prop, reca);
digestRecordIntoProperty(prop, recb);
expect(readPropertyValue(prop)).toBe(42);
});
});