Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add peertube, funkwhale and casperlabs automated tests to the grid client using jest #2784

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { FilterOptions, GatewayNameModel, generateString, GridClient, MachinesMo
import { config, getClient } from "../../client_loader";
import { bytesToGB, generateInt, getOnlineNode, log, splitIP } from "../../utils";

jest.setTimeout(1500000);

let gridClient: GridClient;
let deploymentName: string;

beforeAll(async () => {
gridClient = await getClient();
deploymentName = generateString(15);
deploymentName = "cl" + generateString(15);
gridClient.clientOptions.projectName = `casperlabs/${deploymentName}`;
gridClient._connect();
return gridClient;
Expand Down Expand Up @@ -46,10 +44,10 @@ test("TC2683 - Applications: Deploy Casperlabs", async () => {
//Test Data
const name = "gw" + generateString(10).toLowerCase();
const tlsPassthrough = false;
let cpu = generateInt(1, 4);
let memory = generateInt(1, 6);
let rootfsSize = generateInt(0, 2);
let diskSize = generateInt(10, 50);
const cpu = 2;
const memory = 4;
const rootfsSize = 0;
A-Harby marked this conversation as resolved.
Show resolved Hide resolved
const diskSize = 100;
const networkName = generateString(15);
const vmName = generateString(15);
const diskName = generateString(15);
Expand All @@ -72,35 +70,13 @@ test("TC2683 - Applications: Deploy Casperlabs", async () => {
const GatewayNode = gatewayNodes[generateInt(0, gatewayNodes.length - 1)];

//Node Selection
let nodes;
try {
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
} catch (error) {
//Log the resources that were not found.
log("A Node was not found with the generated resources." + error);
log("Regenerating test data with lower resources....");

//Generate lower resources.
cpu = generateInt(1, cpu);
memory = generateInt(1, memory);
rootfsSize = generateInt(0, rootfsSize);
diskSize = generateInt(5, diskSize);

//Search for another node with lower resources.
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
}
const nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
const nodeId = await getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");
const domain = name + "." + GatewayNode.publicConfig.domain;
Expand Down Expand Up @@ -211,7 +187,10 @@ test("TC2683 - Applications: Deploy Casperlabs", async () => {
const site = "https://" + gatewayResult[0].domain;
let reachable = false;

for (let i = 0; i < 300; i++) {
for (let i = 0; i < 180; i++) {
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);

axios
.get(site)
.then(() => {
Expand All @@ -224,8 +203,6 @@ test("TC2683 - Applications: Deploy Casperlabs", async () => {
if (reachable) {
break;
}
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);
}

if (reachable) {
Expand Down
55 changes: 16 additions & 39 deletions packages/grid_client/tests/modules/applications/funkwhale.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { FilterOptions, GatewayNameModel, generateString, GridClient, MachinesMo
import { config, getClient } from "../../client_loader";
import { bytesToGB, generateInt, getOnlineNode, log, splitIP } from "../../utils";

jest.setTimeout(1500000);

let gridClient: GridClient;
let deploymentName: string;

beforeAll(async () => {
gridClient = await getClient();
deploymentName = generateString(15);
deploymentName = "fw" + generateString(15);
gridClient.clientOptions.projectName = `funkwhale/${deploymentName}`;
gridClient._connect();
return gridClient;
Expand Down Expand Up @@ -46,10 +44,10 @@ test("TC2685 - Applications: Deploy Funkwhale", async () => {
//Test Data
const name = "gw" + generateString(10).toLowerCase();
const tlsPassthrough = false;
let cpu = generateInt(1, 4);
let memory = generateInt(1, 6);
let rootfsSize = generateInt(0, 2);
let diskSize = generateInt(10, 50);
const cpu = 1;
const memory = 2;
const rootfsSize = 0;
const diskSize = 50;
const networkName = generateString(15);
const vmName = generateString(15);
const diskName = generateString(15);
Expand All @@ -72,35 +70,13 @@ test("TC2685 - Applications: Deploy Funkwhale", async () => {
const GatewayNode = gatewayNodes[generateInt(0, gatewayNodes.length - 1)];

//Node Selection
let nodes;
try {
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
} catch (error) {
//Log the resources that were not found.
log("A Node was not found with the generated resources." + error);
log("Regenerating test data with lower resources....");

//Generate lower resources.
cpu = generateInt(1, cpu);
memory = generateInt(1, memory);
rootfsSize = generateInt(0, rootfsSize);
diskSize = generateInt(5, diskSize);

//Search for another node with lower resources.
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
}
const nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
const nodeId = await getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");
const domain = name + "." + GatewayNode.publicConfig.domain;
Expand Down Expand Up @@ -214,7 +190,10 @@ test("TC2685 - Applications: Deploy Funkwhale", async () => {
const site = "https://" + gatewayResult[0].domain;
let reachable = false;

for (let i = 0; i < 300; i++) {
for (let i = 0; i < 180; i++) {
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);

axios
.get(site)
.then(() => {
Expand All @@ -227,8 +206,6 @@ test("TC2685 - Applications: Deploy Funkwhale", async () => {
if (reachable) {
break;
}
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);
}

if (reachable) {
Expand Down
61 changes: 17 additions & 44 deletions packages/grid_client/tests/modules/applications/peertube.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { FilterOptions, GatewayNameModel, generateString, GridClient, MachinesMo
import { config, getClient } from "../../client_loader";
import { bytesToGB, generateInt, getOnlineNode, log, splitIP } from "../../utils";

jest.setTimeout(1500000);

let gridClient: GridClient;
let deploymentName: string;

beforeAll(async () => {
gridClient = await getClient();
deploymentName = generateString(15);
deploymentName = "pt" + generateString(15);
gridClient.clientOptions.projectName = `peertube/${deploymentName}`;
gridClient._connect();
return gridClient;
Expand Down Expand Up @@ -46,10 +44,10 @@ test("TC2684 - Applications: Deploy Peertube", async () => {
//Test Data
const name = "gw" + generateString(10).toLowerCase();
const tlsPassthrough = false;
let cpu = generateInt(1, 4);
let memory = generateInt(1, 6);
let rootfsSize = generateInt(0, 2);
let diskSize = generateInt(10, 50);
const cpu = 1;
const memory = 2;
const rootfsSize = 0;
const diskSize = 15;
const networkName = generateString(15);
const vmName = generateString(15);
const diskName = generateString(15);
Expand All @@ -72,35 +70,13 @@ test("TC2684 - Applications: Deploy Peertube", async () => {
const GatewayNode = gatewayNodes[generateInt(0, gatewayNodes.length - 1)];

//Node Selection
let nodes;
try {
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
} catch (error) {
//Log the resources that were not found.
log("A Node was not found with the generated resources." + error);
log("Regenerating test data with lower resources....");

//Generate lower resources.
cpu = generateInt(1, cpu);
memory = generateInt(1, memory);
rootfsSize = generateInt(0, rootfsSize);
diskSize = generateInt(5, diskSize);

//Search for another node with lower resources.
nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
}
const nodes = await gridClient.capacity.filterNodes({
cru: cpu,
mru: memory,
sru: rootfsSize + diskSize,
farmId: 1,
availableFor: await gridClient.twins.get_my_twin_id(),
} as FilterOptions);
const nodeId = await getOnlineNode(nodes);
if (nodeId == -1) throw new Error("no nodes available to complete this test");
const domain = name + "." + GatewayNode.publicConfig.domain;
Expand Down Expand Up @@ -215,13 +191,12 @@ test("TC2684 - Applications: Deploy Peertube", async () => {
const header =
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";

for (let i = 0; i < 300; i++) {
for (let i = 0; i < 180; i++) {
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);

axios
.get(site, {
headers: {
Accept: header,
},
})
.get(site)
.then(() => {
log("gateway is reachable");
reachable = true;
Expand All @@ -232,8 +207,6 @@ test("TC2684 - Applications: Deploy Peertube", async () => {
if (reachable) {
break;
}
const wait = await setTimeout(5000, "Waiting for gateway to be ready");
log(wait);
}

if (reachable) {
Expand Down
Loading