Skip to content

Commit

Permalink
Fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladsud committed Apr 2, 2021
1 parent f8399e3 commit 1b4fb33
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 4 additions & 3 deletions packages/drivers/local-driver/src/localDeltaStorageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export class LocalDeltaStorageService implements api.IDocumentDeltaStorageServic
const query = { documentId: this.id, tenantId: this.tenantId };
query["operation.sequenceNumber"] = {};
query["operation.sequenceNumber"].$gt = from - 1; // from is inclusive
if (to !== undefined) {
query["operation.sequenceNumber"].$lt = to;
}

// This looks like a bug. It used to work without setting $lt key. Now it does not
// Need follow up
query["operation.sequenceNumber"].$lt = to ?? Number.MAX_SAFE_INTEGER;

const allDeltas = await this.databaseManager.getDeltaCollection(this.tenantId, this.id);
const dbDeltas = await allDeltas.find(query, { "operation.sequenceNumber": 1 });
Expand Down
12 changes: 8 additions & 4 deletions packages/test/local-server-tests/src/test/noDeltaStream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ describe("No Delta Stream", () => {
return container;
}

async function loadContainer(storageOnly: boolean): Promise<IContainer> {
async function loadContainer(storageOnly: boolean, track = true): Promise<IContainer> {
const service = new LocalDocumentServiceFactory(deltaConnectionServer, { storageOnly });
const loader = createLoader(
[[codeDetails, factory]],
new LocalDocumentServiceFactory(deltaConnectionServer, { storageOnly }),
service,
new LocalResolver());
loaderContainerTracker.add(loader);
if (track) {
loaderContainerTracker.add(loader);
}
const container = await loader.resolve({ url: documentLoadUrl });
await loaderContainerTracker.ensureSynchronized();
return container;
}

Expand Down Expand Up @@ -116,7 +120,7 @@ describe("No Delta Stream", () => {
});

it("doesn't affect normal containers", async () => {
await loadContainer(true) as Container;
await loadContainer(true, false) as Container;
const normalContainer1 = await loadContainer(false) as Container;
const normalContainer2 = await loadContainer(false) as Container;
const normalDataObject1 = await requestFluidObject<ITestFluidObject>(normalContainer1, "default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("Ops on Reconnect", () => {
/**
* Waits for the "connected" event from the given container.
*/
async function waitForContainerReconnection(container: Container): Promise<void> {
async function waitForContainerReconnection(container: IContainer): Promise<void> {
await new Promise<void>((resolve) => container.once("connected", () => resolve()));
}

Expand Down Expand Up @@ -102,6 +102,7 @@ describe("Ops on Reconnect", () => {
async function setupSecondContainersDataObject(): Promise<ITestFluidObject> {
const loader = await createLoader();
const container2 = await loader.resolve({ url: documentLoadUrl });
await waitForContainerReconnection(container2);
container2.on("op", (containerMessage: ISequencedDocumentMessage) => {
if (!isRuntimeMessage(containerMessage)) {
return;
Expand Down

0 comments on commit 1b4fb33

Please sign in to comment.