Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable timeout ensureSynchronized everywhere (Solution #2) #12303

Merged
merged 13 commits into from
Oct 15, 2022
5 changes: 2 additions & 3 deletions api-report/mocha-test-setup.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
// @public (undocumented)
export const mochaHooks: {
beforeAll(): void;
beforeEach(): void;
afterEach(): void;
beforeEach(this: Mocha.Context): void;
afterEach(this: Mocha.Context): void;
};


// (No @packageDocumentation comment for this package)

```
1,708 changes: 854 additions & 854 deletions experimental/PropertyDDS/packages/property-dds/src/test/rebasing.spec.ts

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions lerna-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/drivers/odsp-driver/src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ describe("Binary WireFormat perf", () => {

const parseTime = performance.now() - start;
console.log("Binary Format medium snapshot parse time ", parseTime);
});
}).timeout(3000); // This can take more time if running in parallel
});
8 changes: 4 additions & 4 deletions packages/test/mocha-test-setup/mocharc-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
const moduleDir = `${packageDir}/node_modules`;

const requiredModules = [
...(additionalRequiredModules ? additionalRequiredModules : []),
// General mocha setup e.g. suppresses console.log
// Moved to last in required modules, so that aria logger will be ready to access in mochaHooks.ts
// General mocha setup e.g. suppresses console.log,
// This has to be before others (except logger) so that registerMochaTestWrapperFuncs is available
`@fluidframework/mocha-test-setup`,
...(additionalRequiredModules ? additionalRequiredModules : []),
];

// mocha install node_modules directory might not be the same as the module required because of hoisting
Expand All @@ -32,7 +32,7 @@ function getFluidTestMochaConfig(packageDir, additionalRequiredModules, testRepo
});

if (process.env.FLUID_TEST_LOGGER_PKG_PATH) {
// Inject implementation of getTestLogger
// Inject implementation of getTestLogger, put it first before mocha-test-setup
requiredModulePaths.unshift(process.env.FLUID_TEST_LOGGER_PKG_PATH);
}

Expand Down
20 changes: 11 additions & 9 deletions packages/test/mocha-test-setup/src/mochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { ITelemetryBufferedLogger } from "@fluidframework/test-driver-definitions";
import { ITelemetryBaseEvent } from "@fluidframework/common-definitions";
import { Context } from "mocha";
import * as mochaModule from "mocha";
import { pkgName } from "./packageVersion";

const testVariant = process.env.FLUID_TEST_VARIANT;
Expand Down Expand Up @@ -52,16 +52,15 @@ export const mochaHooks = {
return currentTestLogger ?? originalLogger;
};
},
beforeEach() {
beforeEach(this: Mocha.Context) {
// Suppress console.log if not verbose mode
if (process.env.FLUID_TEST_VERBOSE === undefined) {
console.log = () => { };
console.error = () => { };
console.warn = () => { };
}
// save the test name can and clear the previous logger (if afterEach didn't get ran and it got left behind)
const context = this as any as Context;
currentTestName = context.currentTest?.fullTitle();
currentTestName = this.currentTest?.fullTitle();
currentTestLogger = undefined;

// send event on test start
Expand All @@ -73,16 +72,15 @@ export const mochaHooks = {
hostName: pkgName,
});
},
afterEach() {
afterEach(this: Mocha.Context) {
// send event on test end
const context = this as any as Context;
originalLogger.send({
category: "generic",
eventName: "fluid:telemetry:Test_end",
testName: currentTestName,
state: context.currentTest?.state,
duration: context.currentTest?.duration,
timedOut: context.currentTest?.timedOut,
state: this.currentTest?.state,
duration: this.currentTest?.duration,
timedOut: this.currentTest?.timedOut,
testVariant,
hostName: pkgName,
});
Expand All @@ -96,3 +94,7 @@ export const mochaHooks = {
currentTestName = undefined;
},
};

globalThis.getMochaModule = () => {
return mochaModule;
};
4 changes: 2 additions & 2 deletions packages/test/test-end-to-end-tests/src/test/blobs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describeFullCompat("blobs", (getTestObjectProvider) => {
const container2 = await provider.loadTestContainer(testContainerConfig);
const dataStore2 = await requestFluidObject<ITestDataObject>(container2, "default");

await provider.ensureSynchronized(this.timeout() / 3);
await provider.ensureSynchronized();

const blobHandle = dataStore2._root.get<IFluidHandle<ArrayBufferLike>>(testKey);
assert(blobHandle);
Expand Down Expand Up @@ -173,7 +173,7 @@ describeFullCompat("blobs", (getTestObjectProvider) => {
// validate on remote container, local container, and container loaded from summary
for (const container of [container1, container2, await provider.loadTestContainer(testContainerConfig)]) {
const dataStore2 = await requestFluidObject<ITestDataObject>(container, "default");
await provider.ensureSynchronized(this.timeout() / 3);
await provider.ensureSynchronized();
const handle = dataStore2._root.get<IFluidHandle<SharedString>>("sharedString");
assert(handle);
const sharedString2 = await handle.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describeFullCompat("SharedCounter", (getTestObjectProvider) => {

// do the increment
incrementer.increment(incrementAmount);
await provider.ensureSynchronized(this.timeout() / 3);
await provider.ensureSynchronized();

// event count is correct
assert.equal(eventCount1, expectedEventCount);
Expand Down
Loading