Skip to content

Commit 1e10ad7

Browse files
committed
server/tests: do not create and start a default proejct for a new account – just uses up resources, when not used, and add delay after creating accounts
1 parent 7585eca commit 1e10ad7

20 files changed

+81
-11
lines changed

src/packages/server/compute/control.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ describe("creates account, project and a test compute server, then control it",
2525
firstName: "User",
2626
lastName: "One",
2727
account_id,
28+
noFirstProject: true,
2829
});
2930
// Only User One:
3031
project_id = await createProject({
3132
account_id,
3233
title: "My First Project",
34+
start: false,
3335
});
36+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
37+
// TODO: it's surely because of using a connection pool instead of a single connection.
38+
await delay(300);
3439
});
3540

3641
let id;

src/packages/server/compute/create-server.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createAccount from "@cocalc/server/accounts/create-account";
55
import createProject from "@cocalc/server/projects/create";
66
import createServer from "./create-server";
77
import { CLOUDS_BY_NAME } from "@cocalc/util/db-schema/compute-servers";
8+
import { delay } from "awaiting";
89

910
beforeAll(async () => {
1011
await initEphemeralDatabase();
@@ -25,12 +26,17 @@ describe("creates account, project and then compute servers in various ways", ()
2526
firstName: "User",
2627
lastName: "One",
2728
account_id,
29+
noFirstProject: true,
2830
});
2931
// Only User One:
3032
project_id = await createProject({
3133
account_id,
3234
title: "My First Project",
35+
start: false,
3336
});
37+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
38+
// TODO: it's surely because of using a connection pool instead of a single connection.
39+
await delay(300);
3440
});
3541

3642
it("creates a compute server for project one and gets it", async () => {

src/packages/server/compute/get-servers.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createAccount from "@cocalc/server/accounts/create-account";
55
import createProject from "@cocalc/server/projects/create";
66
import addUserToProject from "@cocalc/server/projects/add-user-to-project";
77
import createServer from "./create-server";
8+
import { delay } from "awaiting";
89

910
beforeAll(async () => {
1011
await initEphemeralDatabase();
@@ -60,24 +61,34 @@ describe("creates accounts, projects, compute servers, and tests querying", () =
6061
firstName: "User",
6162
lastName: "One",
6263
account_id: account_id1,
64+
noFirstProject: true,
6365
});
6466
await createAccount({
6567
email: "",
6668
password: "xyz",
6769
firstName: "User",
6870
lastName: "Two",
6971
account_id: account_id2,
72+
noFirstProject: true,
7073
});
7174
// Only User One:
7275
project_id1 = await createProject({
7376
account_id: account_id1,
7477
title: "My First Project",
78+
start: false,
7579
});
80+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
81+
// TODO: it's surely because of using a connection pool instead of a single connection.
82+
await delay(300);
7683
// Both users
7784
project_id2 = await createProject({
7885
account_id: account_id2,
7986
title: "My Second Project",
87+
start: false,
8088
});
89+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
90+
// TODO: it's surely because of using a connection pool instead of a single connection.
91+
await delay(300);
8192
await addUserToProject({
8293
account_id: account_id1,
8394
project_id: project_id2,

src/packages/server/compute/maintenance/purchases/close.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
closePurchase,
1818
} from "./close";
1919
import { getPurchase } from "./util";
20+
import { delay } from "awaiting";
2021

2122
beforeAll(async () => {
2223
await initEphemeralDatabase();
@@ -39,12 +40,17 @@ describe("creates account, project, test compute server, and purchase, then clos
3940
firstName: "User",
4041
lastName: "One",
4142
account_id,
43+
noFirstProject: true,
4244
});
4345
// Only User One:
4446
project_id = await createProject({
4547
account_id,
4648
title: "My First Project",
49+
start: false,
4750
});
51+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
52+
// TODO: it's surely because of using a connection pool instead of a single connection.
53+
await delay(300);
4854
});
4955

5056
it("creates compute server on the 'test' cloud", async () => {

src/packages/server/compute/maintenance/purchases/manage-purchases.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ describe("confirm managing of purchases works", () => {
6060
firstName: "User",
6161
lastName: "One",
6262
account_id,
63+
noFirstProject: true,
6364
});
6465
project_id = await createProject({
6566
account_id,
6667
title: "My First Project",
68+
start: false,
6769
});
70+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
71+
// TODO: it's surely because of using a connection pool instead of a single connection.
72+
await delay(300);
6873
const s = {
6974
title: "myserver",
7075
idle_timeout: 15,

src/packages/server/compute/maintenance/purchases/ongoing-purchases.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
MAX_PURCHASE_LENGTH_MS,
2121
} from "./manage-purchases";
2222
import createPurchase from "@cocalc/server/purchases/create-purchase";
23+
import { delay } from "awaiting";
2324

2425
beforeAll(async () => {
2526
await initEphemeralDatabase();
@@ -49,12 +50,17 @@ describe("creates account, project, test compute server, and purchase", () => {
4950
firstName: "User",
5051
lastName: "One",
5152
account_id,
53+
noFirstProject: true,
5254
});
5355
// Only User One:
5456
project_id = await createProject({
5557
account_id,
5658
title: "My First Project",
59+
start: false,
5760
});
61+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
62+
// TODO: it's surely because of using a connection pool instead of a single connection.
63+
await delay(300);
5864
});
5965

6066
let id;

src/packages/server/compute/maintenance/purchases/util.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createProject from "@cocalc/server/projects/create";
55
import createServer from "@cocalc/server/compute/create-server";
66
import { getServer } from "@cocalc/server/compute/get-servers";
77
import { setPurchaseId } from "./util";
8+
import { delay } from "awaiting";
89

910
beforeAll(async () => {
1011
await initEphemeralDatabase();
@@ -26,12 +27,17 @@ describe("creates compute server then sets the purchase id and confirms it", ()
2627
firstName: "User",
2728
lastName: "One",
2829
account_id,
30+
noFirstProject: true,
2931
});
3032
// Only User One:
3133
project_id = await createProject({
3234
account_id,
3335
title: "My First Project",
36+
start: false,
3437
});
38+
// sometimes above isn't noticed below, which is weird, so we put in slight delay.
39+
// TODO: it's surely because of using a connection pool instead of a single connection.
40+
await delay(300);
3541
const s = {
3642
title: "myserver",
3743
idle_timeout: 15,

src/packages/server/licenses/add-to-project.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ describe("test various cases of adding a license to a project", () => {
2424
project_id = await createProject({
2525
account_id: uuid(),
2626
title: "My First Project",
27+
start: false,
2728
});
2829
await addLicenseToProject({ project_id, license_id });
2930
const pool = getPool();
3031
const { rows } = await pool.query(
3132
"SELECT site_license FROM projects WHERE project_id=$1",
32-
[project_id]
33+
[project_id],
3334
);
3435
expect(rows[0].site_license).toEqual({ [license_id]: {} });
3536
});
@@ -39,7 +40,7 @@ describe("test various cases of adding a license to a project", () => {
3940
const pool = getPool();
4041
const { rows } = await pool.query(
4142
"SELECT site_license FROM projects WHERE project_id=$1",
42-
[project_id]
43+
[project_id],
4344
);
4445
expect(rows[0].site_license).toEqual({ [license_id]: {} });
4546
});
@@ -50,7 +51,7 @@ describe("test various cases of adding a license to a project", () => {
5051
const pool = getPool();
5152
const { rows } = await pool.query(
5253
"SELECT site_license FROM projects WHERE project_id=$1",
53-
[project_id]
54+
[project_id],
5455
);
5556
expect(rows[0].site_license).toEqual({
5657
[license_id]: {},
@@ -62,12 +63,12 @@ describe("test various cases of adding a license to a project", () => {
6263
const pool = getPool();
6364
await pool.query(
6465
"UPDATE projects SET site_license='{}' WHERE project_id=$1",
65-
[project_id]
66+
[project_id],
6667
);
6768
await addLicenseToProject({ project_id, license_id });
6869
const { rows } = await pool.query(
6970
"SELECT site_license FROM projects WHERE project_id=$1",
70-
[project_id]
71+
[project_id],
7172
);
7273
expect(rows[0].site_license).toEqual({ [license_id]: {} });
7374
});

src/packages/server/llm/test/models.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ describe("User-defined LLMs", () => {
315315
firstName: "Test",
316316
lastName: "User",
317317
account_id,
318+
noFirstProject: true,
318319
});
319320
accountCreated = true;
320321
}

src/packages/server/projects/collaborators-ownership.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async function createUser(emailPrefix: string): Promise<string> {
5252
firstName: "Test",
5353
lastName: "User",
5454
account_id,
55+
noFirstProject: true,
5556
});
5657
return account_id;
5758
}
@@ -64,6 +65,7 @@ async function createProjectWithOwner(): Promise<{
6465
const projectId = await createProject({
6566
account_id: ownerId,
6667
title: "Ownership test project",
68+
start: false,
6769
});
6870
return { ownerId, projectId };
6971
}

0 commit comments

Comments
 (0)