Skip to content

Commit 681f6b9

Browse files
committed
Merge remote-tracking branch 'origin/master' into sso-exclusive-all
2 parents b5ce711 + f376403 commit 681f6b9

File tree

328 files changed

+19032
-5347
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+19032
-5347
lines changed

src/compute/compute/lib/listings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export async function initListings({
5252
project_id,
5353
compute_server_id,
5454
getListing,
55-
createWatcher: (path: string, debounceMs: number) =>
56-
new Watcher(path, debounceMs),
55+
createWatcher: (path: string, debounce: number) =>
56+
new Watcher(path, { debounce }),
5757
onDeletePath: (path) => {
5858
logger.debug("onDeletePath -- TODO:", { path });
5959
},

src/compute/compute/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"cookie": "^0.5.0",
4343
"debug": "^4.3.2",
4444
"websocketfs": "^0.17.2",
45-
"ws": "^8.13.0"
45+
"ws": "^8.18.0"
4646
},
4747
"homepage": "https://github.com/sagemathinc/cocalc/tree/master/src/packages/compute",
4848
"repository": {

src/compute/pnpm-lock.yaml

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"psql": "export PGHOST=${PGHOST:=$INIT_CWD/data/postgres/socket}; PGUSER='smc' psql",
1414
"database": "cd dev/project && ./start_postgres.py",
1515
"c": "LOGS=/tmp/ DEBUG='cocalc:*' ./scripts/c",
16-
"version-check": "pip3 install typing_extensions mypy && ./workspaces.py version-check && mypy scripts/check_npm_packages.py",
16+
"version-check": "pip3 install typing_extensions mypy || pip3 install --break-system-packages typing_extensions mypy && ./workspaces.py version-check && mypy scripts/check_npm_packages.py",
1717
"test-parallel": "unset DEBUG && pnpm run version-check && cd packages && pnpm run -r --parallel test",
1818
"test": "unset DEBUG && pnpm run version-check && cd packages && pnpm run -r test",
1919
"prettier-all": "cd packages/"

src/packages/api-client/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ the settings of your project.
1010
```sh
1111
export PROJECT_ID=6640ddad-4bdd-4745-8e63-8db74686a20e
1212
export API_KEY=sk-FcnRs3NxsTZROgbF000001
13-
export API_SERVER=http://localhost:9001
13+
export API_SERVER=http://127.0.0.1:9001
1414
```
1515

1616
The run code in node from the shell in the current directory:

src/packages/backend/execute-code.test.ts

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
process.env.COCALC_PROJECT_MONITOR_INTERVAL_S = "1";
7+
// default is much lower, might fail if you have more procs than the default
8+
process.env.COCALC_PROJECT_INFO_PROC_LIMIT = "10000";
79

810
import { executeCode } from "./execute-code";
911

@@ -300,6 +302,147 @@ describe("async", () => {
300302
);
301303
});
302304

305+
// the await case is essentially like the async case above, but it will block for a bit
306+
describe("await", () => {
307+
const check = (s) => {
308+
expect(s.type).toEqual("async");
309+
if (s.type !== "async") return;
310+
expect(s.status).toEqual("completed");
311+
expect(s.elapsed_s).toBeGreaterThan(1);
312+
expect(s.elapsed_s).toBeLessThan(3);
313+
expect(s.exit_code).toBe(0);
314+
expect(s.pid).toBeGreaterThan(1);
315+
expect(s.stdout).toEqual("foo\n");
316+
expect(s.stderr).toEqual("");
317+
};
318+
319+
it("returns when a job finishes", async () => {
320+
const c = await executeCode({
321+
command: "sleep 2; echo 'foo'",
322+
bash: true,
323+
err_on_exit: false,
324+
async_call: true,
325+
});
326+
expect(c.type).toEqual("async");
327+
if (c.type !== "async") return;
328+
const { status, job_id, pid } = c;
329+
expect(status).toEqual("running");
330+
expect(pid).toBeGreaterThan(1);
331+
const t0 = Date.now();
332+
const s = await executeCode({
333+
async_await: true,
334+
async_get: job_id,
335+
async_stats: true,
336+
});
337+
const t1 = Date.now();
338+
// This is the main test: it really waited for at least a second until the job completed
339+
expect((t1 - t0) / 1000).toBeGreaterThan(1);
340+
check(s);
341+
if (s.type !== "async") return;
342+
expect(Array.isArray(s.stats)).toBeTruthy();
343+
});
344+
345+
it("returns immediately if already done", async () => {
346+
const c = await executeCode({
347+
command: "sleep 1.1; echo 'foo'",
348+
bash: true,
349+
err_on_exit: false,
350+
async_call: true,
351+
});
352+
expect(c.type).toEqual("async");
353+
if (c.type !== "async") return;
354+
const { status, job_id, pid } = c;
355+
expect(status).toEqual("running");
356+
expect(pid).toBeGreaterThan(1);
357+
await new Promise((done) => setTimeout(done, 2000));
358+
const s = await executeCode({
359+
async_await: true,
360+
async_get: job_id,
361+
async_stats: true,
362+
});
363+
check(s);
364+
if (s.type !== "async") return;
365+
expect(s.elapsed_s).toBeLessThan(1.5);
366+
});
367+
368+
it("deal with unknown executables", async () => {
369+
const c = await executeCode({
370+
command: "random123unknown99",
371+
err_on_exit: false,
372+
async_call: true,
373+
});
374+
expect(c.type).toEqual("async");
375+
if (c.type !== "async") return;
376+
const { job_id, pid } = c;
377+
expect(pid).toBeUndefined();
378+
const s = await executeCode({
379+
async_await: true,
380+
async_get: job_id,
381+
async_stats: true,
382+
});
383+
expect(s.type).toEqual("async");
384+
if (s.type !== "async") return;
385+
expect(s.exit_code).toBe(1);
386+
expect(s.stderr).toContain("ENOENT");
387+
expect(s.status).toBe("error");
388+
});
389+
390+
it("returns an error", async () => {
391+
const c = await executeCode({
392+
command: "sleep .1; >&2 echo baz; exit 3",
393+
bash: true,
394+
err_on_exit: false,
395+
async_call: true,
396+
});
397+
expect(c.type).toEqual("async");
398+
if (c.type !== "async") return;
399+
const { status, job_id, pid } = c;
400+
expect(status).toEqual("running");
401+
expect(pid).toBeGreaterThan(1);
402+
const t0 = Date.now();
403+
const s = await executeCode({
404+
async_await: true,
405+
async_get: job_id,
406+
async_stats: true,
407+
});
408+
expect((Date.now() - t0) / 1000).toBeGreaterThan(0.05);
409+
expect(s.type).toEqual("async");
410+
if (s.type !== "async") return;
411+
expect(s.stderr).toEqual("baz\n");
412+
expect(s.exit_code).toEqual(3);
413+
expect(s.status).toEqual("completed");
414+
});
415+
416+
it("react to a killed process", async () => {
417+
const c = await executeCode({
418+
command: "sh",
419+
args: ["-c", `echo foo; sleep 1; echo bar;`],
420+
bash: false,
421+
err_on_exit: false,
422+
async_call: true,
423+
});
424+
expect(c.type).toEqual("async");
425+
if (c.type !== "async") return;
426+
const { job_id, pid } = c;
427+
await new Promise((done) => setTimeout(done, 100));
428+
await executeCode({
429+
command: `kill -9 -${pid}`,
430+
bash: true,
431+
});
432+
const s = await executeCode({
433+
async_await: true,
434+
async_get: job_id,
435+
async_stats: true,
436+
});
437+
expect(s.type).toEqual("async");
438+
if (s.type !== "async") return;
439+
expect(s.stderr).toEqual("");
440+
expect(s.stdout).toEqual("foo\n");
441+
expect(s.exit_code).toEqual(0);
442+
expect(s.status).toEqual("completed");
443+
});
444+
});
445+
303446
// we burn a bit of CPU to get the cpu_pct and cpu_secs up
304447
const CPU_PY = `
305448
from time import time

0 commit comments

Comments
 (0)