From d11d90740ff6232dab1b628b972c81cabda6e01f Mon Sep 17 00:00:00 2001 From: Rob Moffat Date: Mon, 23 Sep 2024 13:25:12 +0100 Subject: [PATCH] Sticking plaster waits to avoid careless race condition in many tests --- src/test/common/fdc3.open.ts | 23 +- src/test/v1.2/advanced/fdc3.open.ts | 15 +- src/test/v1.2/fdc3-1_2-utils.ts | 3 +- src/test/v2.0/advanced/fdc3.open.ts | 3 +- src/test/v2.0/advanced/fdc3.raiseIntent.ts | 247 +++++++++--------- src/test/v2.0/support/channels-support-2.0.ts | 7 +- src/test/v2.1/advanced/fdc3.open.ts | 4 +- 7 files changed, 165 insertions(+), 137 deletions(-) diff --git a/src/test/common/fdc3.open.ts b/src/test/common/fdc3.open.ts index 4055bd04..3680ac4c 100644 --- a/src/test/common/fdc3.open.ts +++ b/src/test/common/fdc3.open.ts @@ -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, 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); @@ -19,7 +21,7 @@ export function getCommonOpenTests(control: OpenControl, 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) { @@ -31,19 +33,21 @@ export function getCommonOpenTests(control: OpenControl, 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); @@ -53,8 +57,9 @@ export function getCommonOpenTests(control: OpenControl, 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"); @@ -64,14 +69,14 @@ export function getCommonOpenTests(control: OpenControl, 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) { @@ -79,5 +84,5 @@ export function getCommonOpenTests(control: OpenControl, documentation: str closed = true; } }).timeout(constants.NoListenerTimeout + 2000); - + } diff --git a/src/test/v1.2/advanced/fdc3.open.ts b/src/test/v1.2/advanced/fdc3.open.ts index 6fad6df2..3c06e990 100644 --- a/src/test/v1.2/advanced/fdc3.open.ts +++ b/src/test/v1.2/advanced/fdc3.open.ts @@ -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(); @@ -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); @@ -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); @@ -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) { @@ -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); }); @@ -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); }); diff --git a/src/test/v1.2/fdc3-1_2-utils.ts b/src/test/v1.2/fdc3-1_2-utils.ts index ad188477..3d787bbc 100644 --- a/src/test/v1.2/fdc3-1_2-utils.ts +++ b/src/test/v1.2/fdc3-1_2-utils.ts @@ -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 @@ -58,7 +59,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"})` ); diff --git a/src/test/v2.0/advanced/fdc3.open.ts b/src/test/v2.0/advanced/fdc3.open.ts index e8851563..e2f1c25f 100644 --- a/src/test/v2.0/advanced/fdc3.open.ts +++ b/src/test/v2.0/advanced/fdc3.open.ts @@ -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"); diff --git a/src/test/v2.0/advanced/fdc3.raiseIntent.ts b/src/test/v2.0/advanced/fdc3.raiseIntent.ts index 5547efe0..1a730f2d 100644 --- a/src/test/v2.0/advanced/fdc3.raiseIntent.ts +++ b/src/test/v2.0/advanced/fdc3.raiseIntent.ts @@ -10,122 +10,133 @@ const control = new RaiseIntentControl2_0(); * Details on the mock apps used in these tests can be found in /mock/README.md */ export default () => - describe("fdc3.raiseIntent", () => { - let errorListener: Listener = undefined; - - afterEach(async function afterEach() { - await closeMockAppWindow(this.currentTest.title); - - if (errorListener) { - errorListener.unsubscribe(); - errorListener = undefined; - } - }); - - const RaiseIntentSingleResolve = "(2.0-RaiseIntentSingleResolve) Should start app intent-a when raising intent 'aTestingIntent1' with context 'testContextX'"; - it(RaiseIntentSingleResolve, async () => { - errorListener = await control.listenForError(); - const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); - const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX); - control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); - await result; - }); - - const RaiseIntentTargetedAppResolve = "(2.0-RaiseIntentTargetedAppResolve) Should start app intent-b when raising intent 'sharedTestingIntent1' with context 'testContextX'"; - it(RaiseIntentTargetedAppResolve, async () => { - errorListener = await control.listenForError(); - const result = control.receiveContext(ControlContextType.sharedTestingIntent1ListenerTriggered); - const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent1, ContextType.testContextX, { - appId: IntentApp.IntentAppB, + describe("fdc3.raiseIntent", () => { + let errorListener: Listener = undefined; + + afterEach(async function afterEach() { + await closeMockAppWindow(this.currentTest.title); + + if (errorListener) { + errorListener.unsubscribe(); + errorListener = undefined; + } + }); + + const RaiseIntentSingleResolve = "(2.0-RaiseIntentSingleResolve) Should start app intent-a when raising intent 'aTestingIntent1' with context 'testContextX'"; + it(RaiseIntentSingleResolve, async () => { + errorListener = await control.listenForError(); + const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX); + control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); + await result; + }); + + const RaiseIntentTargetedAppResolve = "(2.0-RaiseIntentTargetedAppResolve) Should start app intent-b when raising intent 'sharedTestingIntent1' with context 'testContextX'"; + it(RaiseIntentTargetedAppResolve, async () => { + errorListener = await control.listenForError(); + const result = control.receiveContext(ControlContextType.sharedTestingIntent1ListenerTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const intentResolution = await control.raiseIntent(Intent.sharedTestingIntent1, ContextType.testContextX, { + appId: IntentApp.IntentAppB, + }); + control.validateIntentResolution(IntentApp.IntentAppB, intentResolution); + await result; + }); + + const RaiseIntentTargetedInstanceResolveOpen = "(2.0-RaiseIntentTargetedInstanceResolveOpen) Should target running instance of intent-a app when raising intent 'aTestingIntent1' with context 'testContextX' after opening intent-a app"; + it(RaiseIntentTargetedInstanceResolveOpen, async () => { + // add app control listeners + errorListener = await control.listenForError(); + const confirmAppOpened = control.receiveContext(ControlContextType.intentAppAOpened); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + + const appIdentifier = await control.openIntentApp(IntentApp.IntentAppA); + await confirmAppOpened; + + const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, appIdentifier); + await result; + control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); + const instances = await control.findInstances(IntentApp.IntentAppA); + control.validateInstances(instances, 1, appIdentifier.instanceId, (await result).instanceId); + }); + + const RaiseIntentTargetedInstanceResolveFindInstances = "(2.0-RaiseIntentTargetedInstanceResolveFindInstances) Should start app intent-a when targeted by raising intent 'aTestingIntent1' with context 'testContextX'"; + it(RaiseIntentTargetedInstanceResolveFindInstances, async () => { + // add app control listeners + errorListener = await control.listenForError(); + const confirmAppOpened = control.receiveContext(ControlContextType.intentAppAOpened); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + + const appIdentifier = await control.openIntentApp(IntentApp.IntentAppA); + const instances = await control.findInstances(IntentApp.IntentAppA); + control.validateInstances(instances, 1, appIdentifier.instanceId); + await confirmAppOpened; + + const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, instances[0]); + await result; + control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); + + const instances2 = await control.findInstances(IntentApp.IntentAppA); + expect(instances2.length).to.be.equal(1); //make sure no other instance is started + }); + + const PrivateChannelsAreNotAppChannels = "(2.0-PrivateChannelsAreNotAppChannels) Cannot create an app channel using a private channel id"; + it(PrivateChannelsAreNotAppChannels, async () => { + errorListener = await control.listenForError(); + const privChan = await control.createPrivateChannel(); + control.validatePrivateChannel(privChan); + const privChan2 = await control.createPrivateChannel(); + control.validatePrivateChannel(privChan2); + + expect(privChan.id).to.not.be.equal(privChan2.id); //check that the ids of both private channels are different + try { + await control.createAppChannel(privChan.id); + assert.fail("No error was not thrown when calling fdc3.getOrCreateChannel(privateChannel.id)"); + } catch (ex) { + expect(ex).to.have.property("message", ChannelError.AccessDenied, `Incorrect error received when calling fdc3.getOrCreateChannel(privateChannel.id). Expected AccessDenied, got ${ex.message}`); + } + + const intentResolution = await control.raiseIntent(Intent.privateChannelIsPrivate, ContextType.privateChannelDetails, undefined, undefined, { key: privChan2.id }); + control.validateIntentResolution(IntentApp.IntentAppJ, intentResolution); + let result = await control.getIntentResult(intentResolution); + control.validateIntentResult(result, IntentResultType.Context, ContextType.privateChannelDetails); + }); + + const PrivateChannelsLifecycleEvents = "(2.0-PrivateChannelsLifecycleEvents) PrivateChannel lifecycle events are triggered when expected"; + it(PrivateChannelsLifecycleEvents, async () => { + errorListener = await control.listenForError(); + const onUnsubscribeReceiver = control.receiveContext(ControlContextType.onUnsubscribeTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const intentResolution = await control.raiseIntent(Intent.kTestingIntent, ContextType.testContextX, { + appId: IntentApp.IntentAppK, + }); + control.validateIntentResolution(IntentApp.IntentAppK, intentResolution); + let result = await control.getIntentResult(intentResolution); + control.validateIntentResult(result, IntentResultType.PrivateChannel); + let listener = await control.receiveContextStreamFromMockApp(result, 1, 5); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + control.unsubscribeListener(listener); + await onUnsubscribeReceiver; //should receive context from privChannel.onUnsubscribe in mock app + const textContextXReceiver = control.receiveContext(ContextType.testContextX); + await wait(300); // ADDED DUE TO RACE CONDITION in intent-support-2.0.ts/receiveContext on line 12. + control.privateChannelBroadcast(result, ContextType.testContextX); + await textContextXReceiver; + const onUnsubscribeReceiver2 = control.receiveContext(ControlContextType.onUnsubscribeTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + const onDisconnectReceiver = control.receiveContext(ControlContextType.onDisconnectTriggered); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + let listener2 = await control.receiveContextStreamFromMockApp(result, 6, 10); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + control.disconnectPrivateChannel(result); + + //confirm that onUnsubscribe and onDisconnect were triggered in intent-k + await onUnsubscribeReceiver2; + await onDisconnectReceiver; + control.unsubscribeListener(listener2); + }); }); - control.validateIntentResolution(IntentApp.IntentAppB, intentResolution); - await result; - }); - - const RaiseIntentTargetedInstanceResolveOpen = "(2.0-RaiseIntentTargetedInstanceResolveOpen) Should target running instance of intent-a app when raising intent 'aTestingIntent1' with context 'testContextX' after opening intent-a app"; - it(RaiseIntentTargetedInstanceResolveOpen, async () => { - // add app control listeners - errorListener = await control.listenForError(); - const confirmAppOpened = control.receiveContext(ControlContextType.intentAppAOpened); - const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); - - const appIdentifier = await control.openIntentApp(IntentApp.IntentAppA); - await confirmAppOpened; - - const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, appIdentifier); - await result; - control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); - const instances = await control.findInstances(IntentApp.IntentAppA); - control.validateInstances(instances, 1, appIdentifier.instanceId, (await result).instanceId); - }); - - const RaiseIntentTargetedInstanceResolveFindInstances = "(2.0-RaiseIntentTargetedInstanceResolveFindInstances) Should start app intent-a when targeted by raising intent 'aTestingIntent1' with context 'testContextX'"; - it(RaiseIntentTargetedInstanceResolveFindInstances, async () => { - // add app control listeners - errorListener = await control.listenForError(); - const confirmAppOpened = control.receiveContext(ControlContextType.intentAppAOpened); - const result = control.receiveContext(ControlContextType.aTestingIntentListenerTriggered); - - const appIdentifier = await control.openIntentApp(IntentApp.IntentAppA); - const instances = await control.findInstances(IntentApp.IntentAppA); - control.validateInstances(instances, 1, appIdentifier.instanceId); - await confirmAppOpened; - - const intentResolution = await control.raiseIntent(Intent.aTestingIntent, ContextType.testContextX, instances[0]); - await result; - control.validateIntentResolution(IntentApp.IntentAppA, intentResolution); - - const instances2 = await control.findInstances(IntentApp.IntentAppA); - expect(instances2.length).to.be.equal(1); //make sure no other instance is started - }); - - const PrivateChannelsAreNotAppChannels = "(2.0-PrivateChannelsAreNotAppChannels) Cannot create an app channel using a private channel id"; - it(PrivateChannelsAreNotAppChannels, async () => { - errorListener = await control.listenForError(); - const privChan = await control.createPrivateChannel(); - control.validatePrivateChannel(privChan); - const privChan2 = await control.createPrivateChannel(); - control.validatePrivateChannel(privChan2); - - expect(privChan.id).to.not.be.equal(privChan2.id); //check that the ids of both private channels are different - try { - await control.createAppChannel(privChan.id); - assert.fail("No error was not thrown when calling fdc3.getOrCreateChannel(privateChannel.id)"); - } catch (ex) { - expect(ex).to.have.property("message", ChannelError.AccessDenied, `Incorrect error received when calling fdc3.getOrCreateChannel(privateChannel.id). Expected AccessDenied, got ${ex.message}`); - } - - const intentResolution = await control.raiseIntent(Intent.privateChannelIsPrivate, ContextType.privateChannelDetails, undefined, undefined, { key: privChan2.id }); - control.validateIntentResolution(IntentApp.IntentAppJ, intentResolution); - let result = await control.getIntentResult(intentResolution); - control.validateIntentResult(result, IntentResultType.Context, ContextType.privateChannelDetails); - }); - - const PrivateChannelsLifecycleEvents = "(2.0-PrivateChannelsLifecycleEvents) PrivateChannel lifecycle events are triggered when expected"; - it(PrivateChannelsLifecycleEvents, async () => { - errorListener = await control.listenForError(); - const onUnsubscribeReceiver = control.receiveContext(ControlContextType.onUnsubscribeTriggered); - const intentResolution = await control.raiseIntent(Intent.kTestingIntent, ContextType.testContextX, { - appId: IntentApp.IntentAppK, - }); - control.validateIntentResolution(IntentApp.IntentAppK, intentResolution); - let result = await control.getIntentResult(intentResolution); - control.validateIntentResult(result, IntentResultType.PrivateChannel); - let listener = await control.receiveContextStreamFromMockApp(result, 1, 5); - control.unsubscribeListener(listener); - await onUnsubscribeReceiver; //should receive context from privChannel.onUnsubscribe in mock app - const textContextXReceiver = control.receiveContext(ContextType.testContextX); - await wait(300); // ADDED DUE TO RACE CONDITION in intent-support-2.0.ts/receiveContext on line 12. - control.privateChannelBroadcast(result, ContextType.testContextX); - await textContextXReceiver; - const onUnsubscribeReceiver2 = control.receiveContext(ControlContextType.onUnsubscribeTriggered); - const onDisconnectReceiver = control.receiveContext(ControlContextType.onDisconnectTriggered); - let listener2 = await control.receiveContextStreamFromMockApp(result, 6, 10); - control.disconnectPrivateChannel(result); - - //confirm that onUnsubscribe and onDisconnect were triggered in intent-k - await onUnsubscribeReceiver2; - await onDisconnectReceiver; - control.unsubscribeListener(listener2); - }); - }); diff --git a/src/test/v2.0/support/channels-support-2.0.ts b/src/test/v2.0/support/channels-support-2.0.ts index b93f2266..42d7f99b 100644 --- a/src/test/v2.0/support/channels-support-2.0.ts +++ b/src/test/v2.0/support/channels-support-2.0.ts @@ -4,6 +4,7 @@ import constants from "../../../constants"; import { ChannelControl, ChannelsAppConfig, ChannelsAppContext } from "../../common/control/channel-control"; import { AppControlContext } from "../../../context-types"; import { closeMockAppWindow, waitForContext } from "../fdc3-2_0-utils"; +import { wait } from "../../../utils"; declare let fdc3: DesktopAgent; @@ -12,7 +13,7 @@ export class ChannelControl2_0 implements ChannelControl { const channels = await fdc3.getUserChannels(); - if(channels.find((channel) => channel.id.indexOf('global') >=0 )) { + if (channels.find((channel) => channel.id.indexOf('global') >= 0)) { assert.fail("Global channel recieved "); } return channels.filter(channel => channel.id.indexOf('global') === -1); @@ -52,7 +53,9 @@ export class ChannelControl2_0 implements ChannelControl { - return await waitForContext("executionComplete", testId, await fdc3.getOrCreateChannel(constants.ControlChannel)); + const out = await waitForContext("executionComplete", testId, await fdc3.getOrCreateChannel(constants.ControlChannel)); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. + return out }; openChannelApp = async (testId: string, channelId: string | undefined, commands: string[], historyItems: number = undefined, notify: boolean = true, contextId?: string) => { diff --git a/src/test/v2.1/advanced/fdc3.open.ts b/src/test/v2.1/advanced/fdc3.open.ts index 1ebf0b4c..c0617824 100644 --- a/src/test/v2.1/advanced/fdc3.open.ts +++ b/src/test/v2.1/advanced/fdc3.open.ts @@ -6,6 +6,7 @@ import { OpenControl2_1 } from "../support/open-support-2.1"; import { DesktopAgent } from "fdc3_2_0"; import { assert, expect } from "chai"; import { ControlContextType } from "../../v2.0/support/intent-support-2.0"; +import { wait } from "../../../utils"; const openDocs = "\r\nDocumentation: " + APIDocumentation2_1 + "\r\nCause:"; const control = new OpenControl2_1(); @@ -26,10 +27,11 @@ export default () => const AOpensBMalformedContext = `(AOpensBMalformedContext) App B listeners receive nothing when passing a malformed context`; it(AOpensBMalformedContext, async () => { const receiver = control.contextReceiver(ControlContextType.contextReceived); + await wait(300) // Added due to nested promise await race condition first observed by Jupnit. await control.openMockApp(openApp.f.name); await receiver; await control.closeMockApp(AOpensBMalformedContext); }); - + });