diff --git a/src/writerecord.test.js b/src/writerecord.test.js index d319f52..c3cb33a 100644 --- a/src/writerecord.test.js +++ b/src/writerecord.test.js @@ -568,4 +568,87 @@ test("Record digestion is order independent", () => { //criss cross records from two other nodes here }); - */ \ No newline at end of file + */ + +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", () => { + 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 = 1; + recb.machineId = "b"; + recb.machineIndex = 1; + recb.anchors = {"a": 1}; + }); + + //Write takes precedence over delete when all else is in conflict. + + 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); + }); +});