-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MergeTree: Add stress for LocalReferences (#9340)
This change leverages the existing stress infra in merge tree, we call them farms as in bug farm as they find lots of bugs. This is in preparation for how we do local reference sliding. related to #1008
- Loading branch information
1 parent
1f8c2bb
commit 8e864f7
Showing
3 changed files
with
154 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
packages/dds/merge-tree/src/test/client.localReferenceFarm.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { strict as assert } from "assert"; | ||
import random from "random-js"; | ||
import { LocalReference, ReferenceType } from ".."; | ||
import { | ||
IMergeTreeOperationRunnerConfig, | ||
removeRange, | ||
runMergeTreeOperationRunner, | ||
generateClientNames, | ||
IConfigRange, | ||
} from "./mergeTreeOperationRunner"; | ||
import { TestClient } from "./testClient"; | ||
import { TestClientLogger } from "./testClientLogger"; | ||
import { doOverRange } from "."; | ||
|
||
const defaultOptions: Record<"initLen" | "modLen", IConfigRange> & IMergeTreeOperationRunnerConfig = { | ||
initLen: {min: 2, max: 4}, | ||
modLen: {min: 1, max: 8}, | ||
opsPerRoundRange: {min: 10, max: 10}, | ||
rounds: 10, | ||
operations: [removeRange], | ||
growthFunc: (input: number) => input * 2, | ||
}; | ||
|
||
describe("MergeTree.Client", () => { | ||
// Generate a list of single character client names, support up to 69 clients | ||
const clientNames = generateClientNames(); | ||
|
||
doOverRange(defaultOptions.initLen, defaultOptions.growthFunc, (initLen)=>{ | ||
doOverRange(defaultOptions.modLen, defaultOptions.growthFunc, (modLen)=>{ | ||
it(`LocalReferenceFarm_${initLen}_${modLen}`, async () => { | ||
const mt = random.engines.mt19937(); | ||
mt.seedWithArray([0xDEADBEEF, 0xFEEDBED, initLen, modLen]); | ||
|
||
const clients: TestClient[] = new Array(3).fill(0).map(()=> new TestClient()); | ||
clients.forEach( | ||
(c, i) => c.startOrUpdateCollaboration(clientNames[i])); | ||
|
||
let seq = 0; | ||
// init with random values | ||
seq = runMergeTreeOperationRunner( | ||
mt, | ||
seq, | ||
clients, | ||
initLen, | ||
defaultOptions, | ||
); | ||
// add local references | ||
const refs: LocalReference[][] = []; | ||
|
||
const validateRefs = (reason: string, workload: () => void)=>{ | ||
const preWorkload = TestClientLogger.toString(clients); | ||
workload(); | ||
for(let c = 1; c < clients.length; c++) { | ||
for(let r = 0; r < refs[c].length; r++) { | ||
const pos0 = refs[0][r].toPosition(); | ||
const posC = refs[c][r].toPosition(); | ||
if(pos0 !== posC) { | ||
assert.equal( | ||
pos0, posC, | ||
`${reason}:\n${preWorkload}\n${TestClientLogger.toString(clients)}`); | ||
} | ||
} | ||
} | ||
// console.log(`${reason}:\n${preWorkload}\n${TestClientLogger.toString(clients)}`) | ||
}; | ||
|
||
validateRefs("Initialize", ()=>{ | ||
clients.forEach((c,i)=>{ | ||
refs.push([]); | ||
for(let t = 0; t < c.getLength(); t++) { | ||
const seg = c.getContainingSegment(t); | ||
const lref = new LocalReference(c, seg.segment, seg.offset, ReferenceType.SlideOnRemove); | ||
c.addLocalReference(lref); | ||
lref.addProperties({t}); | ||
refs[i].push(lref); | ||
} | ||
}); | ||
}); | ||
|
||
validateRefs("After Init Zamboni",()=>{ | ||
// trigger zamboni multiple times as it is incremental | ||
for(let i = clients[0].getCollabWindow().minSeq; i <= seq; i++) { | ||
clients.forEach((c)=>c.updateMinSeq(i)); | ||
} | ||
}); | ||
|
||
validateRefs("After More Ops", ()=>{ | ||
// init with random values | ||
seq = runMergeTreeOperationRunner( | ||
mt, | ||
seq, | ||
clients, | ||
modLen, | ||
defaultOptions, | ||
); | ||
}); | ||
|
||
validateRefs("After Final Zamboni",()=>{ | ||
// trigger zamboni multiple times as it is incremental | ||
for(let i = clients[0].getCollabWindow().minSeq; i <= seq; i++) { | ||
clients.forEach((c)=>c.updateMinSeq(i)); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters