Skip to content

Commit c570481

Browse files
Merge branch 'master' of github.com:sagemathinc/cocalc into feature/7665
2 parents 247e03a + d51e914 commit c570481

File tree

105 files changed

+2521
-886
lines changed

Some content is hidden

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

105 files changed

+2521
-886
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem. **If the screenshots include text, make sure to also include that text separately so that we can copy and paste it and not have to type it in again!**
25+
26+
27+
28+
**Additional context**
29+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Additional context**
20+
Add any other context or screenshots about the feature request here.

src/c.js

Lines changed: 0 additions & 123 deletions
This file was deleted.

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/*
2+
* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3+
* License: MS-RSL – see LICENSE.md for details
4+
*/
5+
6+
process.env.COCALC_PROJECT_MONITOR_INTERVAL_S = "1";
7+
18
import { executeCode } from "./execute-code";
29

310
describe("hello world", () => {
@@ -90,6 +97,27 @@ describe("test timeout", () => {
9097
});
9198
});
9299

100+
describe("test longer execution", () => {
101+
it(
102+
"runs 5 seconds",
103+
async () => {
104+
const t0 = Date.now();
105+
const { stdout, stderr, exit_code } = await executeCode({
106+
command: "sh",
107+
args: ["-c", "echo foo; sleep 5; echo bar"],
108+
err_on_exit: false,
109+
bash: false,
110+
});
111+
expect(stdout).toBe("foo\nbar\n");
112+
expect(stderr).toBe("");
113+
expect(exit_code).toBe(0);
114+
const t1 = Date.now();
115+
expect((t1 - t0) / 1000).toBeGreaterThan(4.9);
116+
},
117+
10 * 1000,
118+
);
119+
});
120+
93121
describe("test env", () => {
94122
it("allows to specify environment variables", async () => {
95123
const { stdout, stderr, type } = await executeCode({
@@ -211,6 +239,7 @@ describe("async", () => {
211239
expect(typeof job_id).toEqual("string");
212240
if (typeof job_id !== "string") return;
213241
await new Promise((done) => setTimeout(done, 250));
242+
// now we check up on the job
214243
const s = await executeCode({ async_get: job_id });
215244
expect(s.type).toEqual("async");
216245
if (s.type !== "async") return;
@@ -224,4 +253,57 @@ describe("async", () => {
224253
);
225254
expect(s.exit_code).toEqual(1);
226255
});
256+
257+
it(
258+
"long running async job",
259+
async () => {
260+
const c = await executeCode({
261+
command: "sh",
262+
args: ["-c", `echo foo; python3 -c '${CPU_PY}'; echo bar;`],
263+
bash: false,
264+
err_on_exit: false,
265+
async_call: true,
266+
});
267+
expect(c.type).toEqual("async");
268+
if (c.type !== "async") return;
269+
const { status, job_id } = c;
270+
expect(status).toEqual("running");
271+
expect(typeof job_id).toEqual("string");
272+
if (typeof job_id !== "string") return;
273+
await new Promise((done) => setTimeout(done, 5500));
274+
// now we check up on the job
275+
const s = await executeCode({ async_get: job_id, async_stats: true });
276+
expect(s.type).toEqual("async");
277+
if (s.type !== "async") return;
278+
expect(s.elapsed_s).toBeGreaterThan(5);
279+
expect(s.exit_code).toBe(0);
280+
expect(s.pid).toBeGreaterThan(1);
281+
expect(s.stats).toBeDefined();
282+
if (!Array.isArray(s.stats)) return;
283+
const pcts = Math.max(...s.stats.map((s) => s.cpu_pct));
284+
const secs = Math.max(...s.stats.map((s) => s.cpu_secs));
285+
const mems = Math.max(...s.stats.map((s) => s.mem_rss));
286+
expect(pcts).toBeGreaterThan(10);
287+
expect(secs).toBeGreaterThan(1);
288+
expect(mems).toBeGreaterThan(1);
289+
expect(s.stdout).toEqual("foo\nbar\n");
290+
// now without stats, after retrieving it
291+
const s2 = await executeCode({ async_get: job_id });
292+
if (s2.type !== "async") return;
293+
expect(s2.stats).toBeUndefined();
294+
// and check, that this is not removing stats entirely
295+
const s3 = await executeCode({ async_get: job_id, async_stats: true });
296+
if (s3.type !== "async") return;
297+
expect(Array.isArray(s3.stats)).toBeTruthy();
298+
},
299+
10 * 1000,
300+
);
227301
});
302+
303+
// we burn a bit of CPU to get the cpu_pct and cpu_secs up
304+
const CPU_PY = `
305+
from time import time
306+
t0=time()
307+
while t0+5>time():
308+
sum([_ for _ in range(10**6)])
309+
`;

0 commit comments

Comments
 (0)