Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should fail if the kernel is dead', async () => {
const tester = new KernelTester();
const kernel = await tester.start();
// Create a promise that resolves when the kernel's status changes to dead
const dead = testEmission(kernel.statusChanged, {
find: () => kernel.status === 'dead'
});
tester.sendStatus(UUID.uuid4(), 'dead');
await dead;
await expectFailure(kernel.interrupt(), 'Kernel is dead');
tester.dispose();
});
});
it('should fail for wrong response status', async () => {
const sessionModel = createSessionModel();
const serverSettings = getRequestHandler(200, sessionModel);
const options = createSessionOptions(sessionModel, serverSettings);
const sessionPromise = Session.startNew(options);
await expectFailure(sessionPromise);
});
it('should throw an error for an error response', async () => {
handleRequest(defaultKernel, 500, {});
const shutdown = defaultKernel.shutdown();
await expectFailure(shutdown, '');
});
it('should fail for an incorrect response', async () => {
const serverSettings = getRequestHandler(201, {});
const configPromise = ConfigSection.create({
name: randomName(),
serverSettings
});
await expectFailure(configPromise, 'Invalid response: 201 Created');
});
});
it('should fail if the session is disposed', async () => {
const session = Session.connectTo(defaultSession.model);
session.dispose();
await expectFailure(session.shutdown(), 'Session is disposed');
});
it('should fail for improper model', async () => {
handleRequest(defaultSession, 200, {});
await expectFailure(defaultSession.setName(UUID.uuid4()));
});
it('should fail for an incorrect response', async () => {
handleRequest(contents, 204, DEFAULT_FILE);
const save = contents.save('/foo', { type: 'file', name: 'test' });
await expectFailure(save, 'Invalid response: 204 No Content');
});
});
it('should handle an improper name', async () => {
const R_SPEC = JSON.parse(JSON.stringify(PYTHON_SPEC));
R_SPEC.name = 1;
const serverSettings = getRequestHandler(200, {
default: 'R',
kernelspecs: { R: R_SPEC }
});
const promise = KernelSpecAPI.getSpecs(serverSettings);
await expectFailure(promise, 'No valid kernelspecs found');
});
it('should throw an error for an invalid response', async () => {
const settings = getRequestHandler(201, {});
const promise = Kernel.listRunning(settings);
await expectFailure(promise, 'Invalid response: 201 Created');
});
it('should throw an error for an invalid response', async () => {
const data = { id: UUID.uuid4(), name: 'foo' };
const serverSettings = getRequestHandler(200, data);
const kernelPromise = Kernel.startNew({ serverSettings });
await expectFailure(kernelPromise, 'Invalid response: 200 OK');
});