From 36c55a5ff48fbe6dc444378c8d6d04630ab104b1 Mon Sep 17 00:00:00 2001 From: Diego Colombo Date: Fri, 26 May 2023 22:30:40 +0100 Subject: [PATCH] test delay --- .../tests/kernel-client.test.ts | 18 +++++++++++------- .../tests/testSupport.ts | 4 ++++ .../tests/kernelRouting.test.ts | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/polyglot-notebooks-browser/tests/kernel-client.test.ts b/src/polyglot-notebooks-browser/tests/kernel-client.test.ts index 775ee0ade3..02731a9579 100644 --- a/src/polyglot-notebooks-browser/tests/kernel-client.test.ts +++ b/src/polyglot-notebooks-browser/tests/kernel-client.test.ts @@ -4,7 +4,7 @@ import { expect } from "chai"; import { createDotnetInteractiveClient } from "../src/kernel-client-impl"; import * as fetchMock from "fetch-mock"; -import { configureFetchForKernelDiscovery, createMockChannel, MockKernelCommandAndEventChannel, asKernelClientContainer } from "./testSupport"; +import { configureFetchForKernelDiscovery, createMockChannel, MockKernelCommandAndEventChannel, asKernelClientContainer, delay } from "./testSupport"; import * as contracts from "../src/polyglot-notebooks/contracts"; import { IKernelCommandInvocation, Kernel } from "../src/polyglot-notebooks/kernel"; import { attachKernelToChannel } from "../src/kernel-factory"; @@ -127,9 +127,9 @@ describe("polyglot-notebooks", () => { const rootUrl = "https://dotnet.interactive.com:999"; let transport: MockKernelCommandAndEventChannel | undefined; let kernel: Kernel | undefined; - let commandsSentToKernel: contracts.KernelCommandEnvelope[] | undefined; - let kernelEventHandlers: contracts.KernelEventEnvelopeObserver[] | undefined; - let registeredCommandHandlers: { [commandType: string]: ((kernelCommandInvocation: { command: contracts.KernelCommand, context: KernelInvocationContext }) => Promise) } | undefined; + let commandsSentToKernel: contracts.KernelCommandEnvelope[] = []; + let kernelEventHandlers: contracts.KernelEventEnvelopeObserver[] = []; + let registeredCommandHandlers: { [commandType: string]: ((kernelCommandInvocation: { command: contracts.KernelCommand, context: KernelInvocationContext }) => Promise) } = {}; let makeClient = () => { configureFetchForKernelDiscovery(rootUrl); @@ -141,14 +141,13 @@ describe("polyglot-notebooks", () => { return mock; }, clientSideKernelFactory: async (kernelTransport) => { - commandsSentToKernel = []; - kernelEventHandlers = []; - registeredCommandHandlers = {}; + kernel = new Kernel("client-side-kernel"); kernel.registerCommandHandler({ commandType: "CustomCommand", handle: (commandInvocation: IKernelCommandInvocation) => { commandsSentToKernel!.push(commandInvocation.commandEnvelope); + commandsSentToKernel;//? return Promise.resolve(); } }); @@ -186,7 +185,11 @@ describe("polyglot-notebooks", () => { commandType, command: commandIn }; + transport!.fakeIncomingSubmitCommand(commandEnvelopeIn); + await delay(500); + commandsSentToKernel;//? + expect(commandsSentToKernel!.length).to.equal(1); expect(commandsSentToKernel![0].commandType).to.equal("CustomCommand"); @@ -233,6 +236,7 @@ describe("polyglot-notebooks", () => { event: eventIn }; + await delay(500); const publishedEvents = transport!.eventsPublished.filter(e => e.eventType === eventEnvelopeIn.eventType); expect(publishedEvents.length).to.equal(1); expect(publishedEvents[0].eventType).to.be.equal(eventEnvelopeIn.eventType); diff --git a/src/polyglot-notebooks-browser/tests/testSupport.ts b/src/polyglot-notebooks-browser/tests/testSupport.ts index 2417e87272..a93f0ec6f0 100644 --- a/src/polyglot-notebooks-browser/tests/testSupport.ts +++ b/src/polyglot-notebooks-browser/tests/testSupport.ts @@ -113,3 +113,7 @@ export function findEventEnvelope(kernelEventEnvelopes: contracts.KernelEventEnv export function findEventEnvelopeFromKernel(kernelEventEnvelopes: contracts.KernelEventEnvelope[], eventType: contracts.KernelEventType, kernelName: string): contracts.KernelEventEnvelope | undefined { return kernelEventEnvelopes.find(eventEnvelope => eventEnvelope.eventType === eventType && eventEnvelope.command!.command.targetKernelName === kernelName); } + +export function delay(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); +} \ No newline at end of file diff --git a/src/polyglot-notebooks/tests/kernelRouting.test.ts b/src/polyglot-notebooks/tests/kernelRouting.test.ts index 16d1f3b4a2..1e0b68e939 100644 --- a/src/polyglot-notebooks/tests/kernelRouting.test.ts +++ b/src/polyglot-notebooks/tests/kernelRouting.test.ts @@ -114,8 +114,8 @@ describe("kernelRouting", () => { [ 'kernel://local/?tag=arrived', 'kernel://local/javascript?tag=arrived', - 'kernel://remote/', - 'kernel://remote/javascript', + 'kernel://remote/?tag=arrived', + 'kernel://remote/javascript?tag=arrived', 'kernel://local/javascript', 'kernel://local/' ]);