Skip to content

Commit

Permalink
Merge branch 'conformance-2024-race-conditions' into 2_2_Conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Sep 23, 2024
2 parents 083ba2d + d11d907 commit 6387dfc
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 128 deletions.
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);

}
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
3 changes: 2 additions & 1 deletion src/test/v1.2/fdc3-1_2-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare let fdc3: DesktopAgent;
export async function closeMockAppWindow(testId: string) {
const appControlChannel = await fdc3.getOrCreateChannel(constants.ControlChannel);
const contextPromise = waitForContext("windowClosed", testId, appControlChannel);
await wait(300) // Added due to nested promise await race condition first observed by Jupnit.
await broadcastCloseWindow(testId);
await contextPromise;
await wait(constants.WindowCloseWaitTime); // wait for window to close
Expand Down Expand Up @@ -58,7 +59,7 @@ export const waitForContext = (contextType: string, testId: string, channel: Cha
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
3 changes: 2 additions & 1 deletion src/test/v2.0/advanced/fdc3.open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
Loading

0 comments on commit 6387dfc

Please sign in to comment.