Path: blob/master/src/packages/jupyter/stateless-api/kernel-ulimit.test.ts
1447 views
/*1Testing that ulimit is set on the kernels.2*/34import { getPythonKernelName } from "../kernel/kernel-data";5import Kernel from "./kernel";6import { until } from "@cocalc/util/async-utils";78const SECONDS = 2;910jest.setTimeout(10000);11describe("ulimit is set on the stateless api kernels (and can be configured)", () => {12let kernel;13let kernelName;1415it(`modifies the pool params so the ulimit is ${SECONDS} second of CPU usage`, async () => {16kernelName = await getPythonKernelName();17Kernel.setUlimit(kernelName, `-t ${SECONDS}`);18});1920it("gets a kernel", async () => {21// repeat because in rare cases the kernel already in the pool may22// get the ulimit from starting up python (1s of cpu time is short!)23await until(24async () => {25try {26kernel = await Kernel.getFromPool(kernelName);27return true;28} catch {29return false;30}31},32{ start: 1000 },33);34});3536it("quick eval works", async () => {37const output = await kernel.execute("389+11");38expect(output[0].data["text/plain"]).toBe("400");39});4041it(`something that takes infinite CPU time gets killed in at most ${SECONDS} seconds`, async () => {42const start = Date.now();43try {44await kernel.execute("while True: sum(range(10**8))");45} catch (err) {46expect(`${err}`).toContain("Kernel last exited with code 137.");47}48expect(Date.now() - start).toBeLessThan(SECONDS * 1500);49});5051it("cleans up", () => {52kernel.close();53});54});555657