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

Sticking plaster waits to avoid careless race condition in many tests #262

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,882 changes: 945 additions & 2,937 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/test/common/fdc3.app-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { APP_CHANNEL_AND_BROADCAST, APP_CHANNEL_AND_BROADCAST_TWICE, ChannelCont

export function createAppChannelTests(cc: ChannelControl<any, any, any>, documentation: string, prefix: string): Mocha.Suite {
return describe("App channels", () => {
beforeEach(cc.leaveChannel);
beforeEach(async () => cc.leaveChannel());

afterEach(async function afterEach() {
await cc.closeMockApp(this.currentTest.title);
Expand Down Expand Up @@ -167,7 +167,7 @@ export function createAppChannelTests(cc: ChannelControl<any, any, any>, documen
}
}
} finally {
cc.unsubscribeListeners([listener,listener2]);
cc.unsubscribeListeners([listener, listener2]);
}
});

Expand Down
23 changes: 14 additions & 9 deletions src/test/common/fdc3.open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { assert } from "chai";
import constants from "../../constants";
import { openApp, OpenCommonConfig, OpenControl } from "./control/open-control";
import { ControlContextType } from "../v2.0/support/intent-support-2.0";
import { wait } from "../../utils";

export function getCommonOpenTests(control: OpenControl<any>, documentation: string, config: OpenCommonConfig) {

const AOpensB3 = `(${config.prefix}AOpensB3) Can open app B from app A with no context and ${config.targetMultiple} as config.target`;
it(AOpensB3, async () => {
let targetApp: any;
targetApp = control.createTargetApp(openApp.b.name,openApp.b.id);
targetApp = control.createTargetApp(openApp.b.name, openApp.b.id);
const result = control.contextReceiver("fdc3-conformance-opened");
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp);
await result;
await control.closeMockApp(AOpensB3);
Expand All @@ -19,7 +21,7 @@ export function getCommonOpenTests(control: OpenControl<any>, documentation: str
it(AFailsToOpenB3, async () => {
try {
let targetApp: any;
targetApp = control.createTargetApp("ThisAppDoesNotExist","ThisAppDoesNotExist");
targetApp = control.createTargetApp("ThisAppDoesNotExist", "ThisAppDoesNotExist");
await control.openMockApp(targetApp);
assert.fail("No error was not thrown", documentation);
} catch (ex) {
Expand All @@ -31,19 +33,21 @@ export function getCommonOpenTests(control: OpenControl<any>, documentation: str
it(AOpensBWithContext3, async () => {
let context: any, targetApp: any;
context = { type: "fdc3.instrument", name: "context" };
targetApp = control.createTargetApp(openApp.b.name,openApp.b.id);
targetApp = control.createTargetApp(openApp.b.name, openApp.b.id);
const receiver = control.contextReceiver(ControlContextType.contextReceived);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp, context);
await control.validateReceivedContext(await receiver, "fdc3.instrument");
await control.closeMockApp(AOpensBWithContext3);
});

const AOpensBWithSpecificContext = `(${config.prefix}AOpensBWithSpecificContext) Can open app B from app A with context and ${config.targetMultiple} as config.target and app B is expecting context`;
it(AOpensBWithSpecificContext, async () => {
let context: any, targetApp: any;
context = { type: "fdc3.instrument", name: "context" };
targetApp = control.createTargetApp(openApp.b.name,openApp.b.id);
targetApp = control.createTargetApp(openApp.b.name, openApp.b.id);
const receiver = control.contextReceiver(ControlContextType.contextReceived);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp, context);
await control.validateReceivedContext(await receiver, "fdc3.instrument");
await control.closeMockApp(AOpensBWithSpecificContext);
Expand All @@ -53,8 +57,9 @@ export function getCommonOpenTests(control: OpenControl<any>, documentation: str
it(AOpensBMultipleListen, async () => {
let context: any, targetApp: any;
context = { type: "fdc3.instrument", name: "context" };
targetApp = control.createTargetApp(openApp.b.name,openApp.b.id);
targetApp = control.createTargetApp(openApp.b.name, openApp.b.id);
const receiver = control.contextReceiver(ControlContextType.contextReceived);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp, context);
await receiver;
await control.validateReceivedContext(await receiver, "fdc3.instrument");
Expand All @@ -64,20 +69,20 @@ export function getCommonOpenTests(control: OpenControl<any>, documentation: str
const AOpensBWithWrongContext = `(${config.prefix}AOpensBWithWrongContext) Received App timeout when opening app B with fake context, app b listening for different context`;
it(AOpensBWithWrongContext, async () => {
await control.addListenerAndFailIfReceived();
let targetApp = control.createTargetApp(openApp.b.name,openApp.b.id);
let targetApp = control.createTargetApp(openApp.b.name, openApp.b.id);
let closed = false;
setTimeout(() => {
if (!closed) {
control.closeMockApp(AOpensBWithWrongContext);
closed = true;
}
}, constants.NoListenerTimeout+100);
}, constants.NoListenerTimeout + 100);

await control.expectAppTimeoutErrorOnOpen(targetApp);
if (!closed) {
control.closeMockApp(AOpensBWithWrongContext);
closed = true;
}
}).timeout(constants.NoListenerTimeout + 2000);

}
2 changes: 1 addition & 1 deletion src/test/common/fdc3.user-channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import constants from "../../constants";
export function createUserChannelTests(cc: ChannelControl<any, any, any>, documentation: string, prefix: string): Mocha.Suite {
const channelName = prefix === "" ? "System channels" : "User channels";
return describe(channelName, () => {
beforeEach(cc.leaveChannel);
beforeEach(async () => cc.leaveChannel());

afterEach(async function afterEach() {
if (this.currentTest.title !== UCFilteredUsageJoin) await cc.closeMockApp(this.currentTest.title);
Expand Down
15 changes: 10 additions & 5 deletions src/test/v1.2/advanced/fdc3.open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { openApp, OpenCommonConfig } from "../../common/control/open-control";
import { assert } from "chai";
import { APIDocumentation1_2 } from "../apiDocuments-1.2";
import { Context, TargetApp } from "fdc3_1_2";
import { wait } from "../../../utils";

const openDocs = "\r\nDocumentation: " + APIDocumentation1_2.open + "\r\nCause: ";
const control = new OpenControl1_2();
Expand All @@ -26,6 +27,7 @@ export default () =>
it(AOpensB1, async () => {
let targetApp = openApp.b.name;
const result = control.contextReceiver("fdc3-conformance-opened");
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp);
await result;
await control.closeMockApp(AOpensB1);
Expand All @@ -34,8 +36,9 @@ export default () =>
const AOpensB2 = "(AOpensB2) Can open app B from app A with no context and AppMetadata (name) as target";
it(AOpensB2, async () => {
let targetApp: TargetApp;
targetApp = { name: openApp.b.name};
targetApp = { name: openApp.b.name };
const result = control.contextReceiver("fdc3-conformance-opened");
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp);
await result;
await control.closeMockApp(AOpensB2);
Expand All @@ -54,7 +57,7 @@ export default () =>
it(AFailsToOpenB2Test, async () => {
try {
let targetApp: TargetApp;
targetApp = { name: "ThisAppDoesNotExist"};
targetApp = { name: "ThisAppDoesNotExist" };
await control.openMockApp(targetApp);
assert.fail("No error was not thrown", openDocs);
} catch (ex) {
Expand All @@ -68,7 +71,8 @@ export default () =>
context = { type: "fdc3.instrument", name: "context" };
targetApp = openApp.b.name;
const receiver = control.contextReceiver("context-received");
await control.openMockApp(targetApp, context );
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp, context);
await control.validateReceivedContext(await receiver, "fdc3.instrument");
await control.closeMockApp(AOpensBWithContext1);
});
Expand All @@ -77,9 +81,10 @@ export default () =>
it(AOpensBWithContext2, async () => {
let context: Context, targetApp: TargetApp;
context = { type: "fdc3.instrument", name: "context" };
targetApp = { name: openApp.b.name};
targetApp = { name: openApp.b.name };
const receiver = control.contextReceiver("context-received");
await control.openMockApp(targetApp, context );
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await control.openMockApp(targetApp, context);
await control.validateReceivedContext(await receiver, "fdc3.instrument");
await control.closeMockApp(AOpensBWithContext2);
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/v1.2/fdc3-1_2-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const waitForContext = (contextType: string, testId: string, channel?: Ch
else {
console.log(
Date.now() +
` CHecking for current context of type "${contextType}" for test: "${testId}" Current context did ${context ? "" : "NOT "} exist,
` CHecking for current context of type "${contextType}" for test: "${testId}" Current context did ${context ? "" : "NOT "} exist,
had testId: "${context?.testId}" (${testId == context?.testId ? "did match" : "did NOT match"})
and type "${context?.type}" (${context?.type == contextType ? "did match" : "did NOT match"})`
);
Expand Down
2 changes: 2 additions & 0 deletions src/test/v2.0/advanced/fdc3.getAppMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assert, expect } from "chai";
import { APIDocumentation2_0 } from "../apiDocuments-2.0";
import { MetadataFdc3Api, MetadataValidator } from "../support/metadata-support-2.0";
import { closeMockAppWindow } from "../fdc3-2_0-utils";
import { wait } from "../../../utils";

const getMetadataDocs = "\r\nDocumentation: " + APIDocumentation2_0.appMetadata + "\r\nCause: ";
const validator = new MetadataValidator();
Expand All @@ -10,6 +11,7 @@ const api = new MetadataFdc3Api();
export default () =>
describe("fdc3.getAppMetadata", () => {
after(async () => {
await wait(600)
await closeMockAppWindow(appInstanceMetadata);
});

Expand Down
4 changes: 3 additions & 1 deletion src/test/v2.0/advanced/fdc3.open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { APIDocumentation2_0 } from "../apiDocuments-2.0";
import { OpenControl2_0 } from "../support/open-support-2.0";
import { DesktopAgent } from "fdc3_2_0";
import { assert, expect } from "chai";
import { wait } from "../../../utils";

const openDocs = "\r\nDocumentation: " + APIDocumentation2_0 + "\r\nCause:";
const control = new OpenControl2_0();
Expand All @@ -26,7 +27,8 @@ export default () =>
const AOpensB4 = "(AOpensB4) Can open app B from app A with appId as config.target, and recieves the same appId and also contains InstanceId";
it(AOpensB4, async () => {
const result = control.contextReceiver("fdc3-conformance-opened");
const targetApp = {appId:openApp.b.id};
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const targetApp = { appId: openApp.b.id };
const instanceIdentifier = await control.openMockApp(targetApp);
expect(instanceIdentifier.appId).to.eq(openApp.b.id);
expect(instanceIdentifier).to.have.property("instanceId");
Expand Down
10 changes: 8 additions & 2 deletions src/test/v2.0/advanced/fdc3.raiseIntent-Result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ const control = new RaiseIntentControl2_0();

export default () =>

describe("fdc3.raiseIntent (Result)", () => {
describe("fdc3.raiseIntent (Result)", () => {
let errorListener: Listener = undefined;

afterEach(async function afterEach() {
await closeMockAppWindow(this.currentTest.title);

Expand All @@ -33,6 +33,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentVoidResult5secs, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered, 8000);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, undefined, 5000);
control.validateIntentResolution(IntentApp.IntentAppA, intentResolution);
let intentResultPromise = control.getIntentResult(intentResolution);
Expand All @@ -57,6 +58,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentContextResult5secs, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.sharedTestingIntent1ListenerTriggered, 8000);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent1, ContextType.testContextY, undefined, 5000);
control.validateIntentResolution(IntentApp.IntentAppB, intentResolution);
const intentResultPromise = control.getIntentResult(intentResolution);
Expand All @@ -72,6 +74,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentChannelResult, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.sharedTestingIntent2ResultSent, constants.WaitTime);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent2, ContextType.testContextY, {
appId: IntentApp.IntentAppE,
});
Expand All @@ -89,6 +92,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentPrivateChannelResult, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.sharedTestingIntent2ResultSent, constants.WaitTime);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent2, ContextType.testContextY, {
appId: IntentApp.IntentAppF,
});
Expand All @@ -106,6 +110,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentVoidResult61secs, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered, 64000);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, undefined, 61000);
control.validateIntentResolution(IntentApp.IntentAppA, intentResolution);
let intentResultPromise = control.getIntentResult(intentResolution);
Expand All @@ -121,6 +126,7 @@ describe("fdc3.raiseIntent (Result)", () => {
it(RaiseIntentContextResult61secs, async () => {
errorListener = await control.listenForError();
let receiver = control.receiveContext(ControlContextType.sharedTestingIntent1ListenerTriggered, 64000);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent1, ContextType.testContextY, undefined, 61000);
control.validateIntentResolution(IntentApp.IntentAppB, intentResolution);
let intentResultPromise = control.getIntentResult(intentResolution);
Expand Down
Loading
Loading