Skip to content

Commit

Permalink
test delay
Browse files Browse the repository at this point in the history
  • Loading branch information
colombod committed May 26, 2023
1 parent 0765c85 commit 36c55a5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/polyglot-notebooks-browser/tests/kernel-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<void>) } | undefined;
let commandsSentToKernel: contracts.KernelCommandEnvelope[] = [];
let kernelEventHandlers: contracts.KernelEventEnvelopeObserver[] = [];
let registeredCommandHandlers: { [commandType: string]: ((kernelCommandInvocation: { command: contracts.KernelCommand, context: KernelInvocationContext }) => Promise<void>) } = {};

let makeClient = () => {
configureFetchForKernelDiscovery(rootUrl);
Expand All @@ -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();
}
});
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/polyglot-notebooks-browser/tests/testSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
4 changes: 2 additions & 2 deletions src/polyglot-notebooks/tests/kernelRouting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
]);
Expand Down

0 comments on commit 36c55a5

Please sign in to comment.