|
|
@@ -126,8 +126,8 @@ async function runTest(verbose) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function throwErrorOnFetch() {
|
|
|
- throw new AssertionError("Did not expect async fetch");
|
|
|
+ function noFetch() {
|
|
|
+ throw new AssertionError("Did not expect fetch");
|
|
|
}
|
|
|
|
|
|
{
|
|
|
@@ -135,8 +135,8 @@ async function runTest(verbose) {
|
|
|
|
|
|
|
|
|
// Local and remote are just names for our histories.
|
|
|
- const localContext = new Context(throwErrorOnFetch);
|
|
|
- const remoteContext = new Context(throwErrorOnFetch);
|
|
|
+ const localContext = new Context(noFetch);
|
|
|
+ const remoteContext = new Context(noFetch);
|
|
|
|
|
|
const {history: localHistory, state: localState } = createHistory("local", localContext);
|
|
|
const {history: remoteHistory, state: remoteState} = createHistory("remote", remoteContext);
|
|
|
@@ -153,8 +153,8 @@ async function runTest(verbose) {
|
|
|
{
|
|
|
info("\nTest case: Concurrency with conflict\n")
|
|
|
|
|
|
- const localContext = new Context(throwErrorOnFetch);
|
|
|
- const remoteContext = new Context(throwErrorOnFetch);
|
|
|
+ const localContext = new Context(noFetch);
|
|
|
+ const remoteContext = new Context(noFetch);
|
|
|
|
|
|
const {history: localHistory, state: localState} = createHistory("local", localContext);
|
|
|
const {history: remoteHistory, state: remoteState} = createHistory("remote", remoteContext);
|
|
|
@@ -171,8 +171,8 @@ async function runTest(verbose) {
|
|
|
{
|
|
|
info("\nTest case: Concurrency with conflict (2)\n")
|
|
|
|
|
|
- const localContext = new Context(throwErrorOnFetch);
|
|
|
- const remoteContext = new Context(throwErrorOnFetch);
|
|
|
+ const localContext = new Context(noFetch);
|
|
|
+ const remoteContext = new Context(noFetch);
|
|
|
|
|
|
const {history: localHistory, state: localState} = createHistory("local", localContext);
|
|
|
const {history: remoteHistory, state: remoteState} = createHistory("remote", remoteContext);
|
|
|
@@ -195,6 +195,44 @@ async function runTest(verbose) {
|
|
|
|
|
|
assert(deepEqual(localState, remoteState));
|
|
|
}
|
|
|
+
|
|
|
+ {
|
|
|
+ info("\nTest case: Fetch\n")
|
|
|
+
|
|
|
+ const fetched = [];
|
|
|
+
|
|
|
+ async function fetchFromLocal(id) {
|
|
|
+ // console.log("fetching", id)
|
|
|
+ fetched.push(id);
|
|
|
+ return localContext.ops.get(id).then(op => op.serialize());
|
|
|
+ }
|
|
|
+
|
|
|
+ const localContext = new Context(noFetch);
|
|
|
+ const remoteContext = new Context(fetchFromLocal);
|
|
|
+
|
|
|
+ const {history: localHistory, state: localState} = createHistory("local", localContext);
|
|
|
+
|
|
|
+ const localOps = [
|
|
|
+ localHistory.new({geometry:1}), // [0] (no deps)
|
|
|
+ localHistory.new({geometry:2, style: 3}), // [1], depends on [0]
|
|
|
+ localHistory.new({style: 4}), // [2], depends on [1]
|
|
|
+ localHistory.new({geometry: 5, style: 6, parent: 7}), // [3], depends on [1], [2]
|
|
|
+ localHistory.new({parent: 8}), // [4], depends on [3]
|
|
|
+ localHistory.new({terminal: 9}), // [5] (no deps)
|
|
|
+ ];
|
|
|
+
|
|
|
+ // when given [2], should fetch [1], then [0]
|
|
|
+ await remoteContext.receiveOperation(localOps[2].serialize());
|
|
|
+ assert(deepEqual(fetched, [localOps[1].id, localOps[0].id]));
|
|
|
+
|
|
|
+ // when given [5], should not fetch anything
|
|
|
+ await remoteContext.receiveOperation(localOps[5].serialize());
|
|
|
+ assert(deepEqual(fetched, [localOps[1].id, localOps[0].id]));
|
|
|
+
|
|
|
+ // when given [4], should fetch [3]. (already have [0-2] from previous step)
|
|
|
+ await remoteContext.receiveOperation(localOps[4].serialize());
|
|
|
+ assert(deepEqual(fetched, [localOps[1].id, localOps[0].id, localOps[3].id]));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
runTest(/* verbose: */ true).then(() => {
|