Skip to content

Commit 635a6f2

Browse files
author
Guilherme Saraiva
committed
Fix CRUD Rest tests
This patch fixes the CRUD tests by relying only on the router icon on the tree, to check if its active or not. Change-Id: I64705a501445e2a5f4b74a56d2a5a6cce1c480ff
1 parent acb8650 commit 635a6f2

File tree

4 files changed

+32
-78
lines changed

4 files changed

+32
-78
lines changed

gui/extension/tests/e2e/lib/db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ export class Database {
11951195
if (restObject.jsonRelDuality) {
11961196
if (restObject.jsonRelDuality.dbObject) {
11971197
const inDbObj = await dialog.findElement(locator.mrsDbObjectDialog.jsonDuality.dbObject);
1198-
await inDbObj.clear();
1198+
await this.clearInputField(inDbObj);
11991199
await inDbObj.sendKeys(restObject.jsonRelDuality.dbObject);
12001200
}
12011201
if (restObject.jsonRelDuality.sdkLanguage) {

gui/extension/tests/e2e/lib/misc.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { spawnSync, execSync } from "child_process";
2525
import clipboard from "clipboardy";
2626
import fs from "fs/promises";
2727
import addContext from "mochawesome/addContext";
28-
import { platform } from "os";
28+
import { hostname, platform } from "os";
2929
import { join } from "path";
3030
import {
3131
BottomBarPanel, Condition, CustomTreeSection, EditorView, error, InputBox, ITimeouts,
@@ -938,7 +938,7 @@ export class Misc {
938938
}
939939
};
940940

941-
public static isRouterRunning = (): boolean => {
941+
public static isRouterProcessRunning = (): boolean => {
942942
if (Misc.isWindows()) {
943943
const cmdResult = execSync(`tasklist /fi "IMAGENAME eq mysqlrouter.exe"`);
944944
const resultLines = cmdResult.toString().split("\n");
@@ -962,6 +962,13 @@ export class Misc {
962962
}
963963
};
964964

965+
public static isRouterIconActive = async (): Promise<boolean> => {
966+
const routerItem = await Misc.getTreeElement(constants.dbTreeSection, new RegExp(hostname()));
967+
const icon = await routerItem.findElement(locator.section.itemIcon);
968+
969+
return (await icon.getCssValue("background-image")).match(/router.svg/) !== null;
970+
};
971+
965972
public static routerHasError = async (treeItem: TreeItem): Promise<boolean> => {
966973
const icon = await treeItem.findElement(locator.section.itemIcon);
967974
const style = await icon.getAttribute("style");

gui/extension/tests/e2e/lib/until.ts

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
Locator,
3030
Workbench,
3131
} from "vscode-extension-tester";
32-
import { execSync } from "child_process";
3332
import { join } from "path";
3433
import fs from "fs/promises";
3534
import * as constants from "./constants";
@@ -219,46 +218,29 @@ export const notificationsExist = (): Condition<boolean> => {
219218
});
220219
};
221220

222-
export const fetchIsSuccessful = (url: string, data?: RequestInit): Condition<boolean> => {
223-
return new Condition(`for router ${url} to return success`, async () => {
224-
let response: Response;
225-
226-
return driver.wait(async () => {
227-
try {
228-
response = await fetch(url, data);
221+
export const routerProcessIsRunning = (): Condition<boolean> => {
222+
return new Condition("for Router to be running", () => {
223+
return Misc.isRouterProcessRunning();
224+
});
225+
};
229226

230-
await response.json();
227+
export const routerIconIsActive = (): Condition<boolean> => {
228+
return new Condition(`for router icon to be active`, async () => {
229+
const dbSection = await Misc.getSection(constants.dbTreeSection);
230+
await Misc.clickSectionToolbarButton(dbSection, constants.reloadConnections);
231+
await driver.wait(isNotLoading(constants.dbTreeSection), constants.wait5seconds);
231232

232-
return true;
233-
} catch (e) {
234-
// continue
235-
console.log("-------");
236-
console.log(e);
237-
console.log("-------");
238-
}
239-
}, constants.wait5seconds, `Could not get URL for ${url}`);
233+
return Misc.isRouterIconActive();
240234
});
241235
};
242236

243-
export const routerIsRunning = (): Condition<boolean> => {
244-
return new Condition("for Router to be running", () => {
245-
if (Misc.isWindows()) {
246-
const cmdResult = execSync(`tasklist /fi "IMAGENAME eq mysqlrouter.exe"`);
247-
const resultLines = cmdResult.toString().split("\n");
248-
for (const line of resultLines) {
249-
if (line.match(/mysqlrouter.exe/) !== null) {
250-
return true;
251-
}
252-
}
253-
} else {
254-
const cmdResult = execSync("ps aux | grep mysqlrouter");
255-
const resultLines = cmdResult.toString().split("\n");
256-
for (const line of resultLines) {
257-
if (line.match(/\/usr\/.*\/.*router/) !== null) {
258-
return true;
259-
}
260-
}
261-
}
237+
export const routerIconIsInactive = (): Condition<boolean> => {
238+
return new Condition(`for router icon to be inactive`, async () => {
239+
const dbSection = await Misc.getSection(constants.dbTreeSection);
240+
await Misc.clickSectionToolbarButton(dbSection, constants.reloadConnections);
241+
await driver.wait(isNotLoading(constants.dbTreeSection), constants.wait5seconds);
242+
243+
return !(await Misc.isRouterIconActive());
262244
});
263245
};
264246

gui/extension/tests/e2e/tests/ui-rest.ts

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe("MySQL REST Service", () => {
236236
expect(await Misc.existsTreeElement(constants.dbTreeSection, new RegExp(hostname()))).to.be.true;
237237
const router = await Misc.getTreeElement(constants.dbTreeSection, new RegExp(hostname()));
238238
expect(await Misc.routerHasError(router), "Please update Router").to.be.false;
239-
expect(Misc.isRouterRunning()).to.be.false;
239+
await driver.wait(waitUntil.routerIconIsInactive(), constants.wait10seconds);
240240
await Misc.setRouterConfig({
241241
sinks: "filelog",
242242
});
@@ -248,9 +248,7 @@ describe("MySQL REST Service", () => {
248248
const treeMySQLRESTService = await Misc.getTreeElement(constants.dbTreeSection, constants.mysqlRestService);
249249
await treeMySQLRESTService.expand();
250250
await Misc.openContextMenuItem(treeMySQLRESTService, constants.startRouter, constants.checkTerminal);
251-
await driver.wait(waitUntil.routerIsRunning(), constants.wait10seconds, "Router should be running");
252-
await driver.wait(waitUntil.existsOnRouterLog("Start accepting connections for routing"),
253-
constants.wait20seconds, "'Start accepting connections for routing' was not found on the router log");
251+
await driver.wait(waitUntil.routerIconIsActive(), constants.wait10seconds);
254252
});
255253

256254
it("Stop Local MySQL Router Instance", async () => {
@@ -259,15 +257,7 @@ describe("MySQL REST Service", () => {
259257
await treeMySQLRESTService.expand();
260258
await fs.truncate(await Misc.getRouterLogFile());
261259
await Misc.openContextMenuItem(treeMySQLRESTService, constants.stopRouter, constants.checkTerminal);
262-
if (Misc.isWindows()) {
263-
await driver.wait(() => {
264-
return !Misc.isRouterRunning();
265-
}, constants.wait10seconds, "Router task should not be running");
266-
} else {
267-
await driver.wait(waitUntil.existsOnRouterLog("Unloading all plugins"),
268-
constants.wait20seconds, "'Unloading all plugins' was not found on the router log");
269-
expect(Misc.isRouterRunning()).to.be.false;
270-
}
260+
await driver.wait(waitUntil.routerIconIsInactive(), constants.wait10seconds);
271261
});
272262

273263
it("Browse the MySQL REST Service Documentation", async () => {
@@ -1021,15 +1011,7 @@ describe("MySQL REST Service", () => {
10211011
await fs.truncate(await Misc.getRouterLogFile());
10221012
treeMySQLRESTService = await Misc.getTreeElement(constants.dbTreeSection, constants.mysqlRestService);
10231013
await Misc.openContextMenuItem(treeMySQLRESTService, constants.startRouter, undefined);
1024-
await driver.wait(waitUntil.routerIsRunning(), constants.wait10seconds, "Router should be running");
1025-
await driver.wait(waitUntil.existsOnRouterLog("Start accepting connections for routing"),
1026-
constants.wait20seconds,
1027-
"'Start accepting connections for routing' was not found on the router log");
1028-
let regExp = `adding_route:.*${crudService.servicePath}`;
1029-
regExp += `${crudSchema.restSchemaPath}${crudObject.restObjectPath}`;
1030-
await driver.wait(waitUntil.existsOnRouterLog(new RegExp(regExp)),
1031-
constants.wait25seconds,
1032-
"'adding route' was not found on the router log");
1014+
await driver.wait(waitUntil.routerIconIsActive(), constants.wait10seconds);
10331015
} catch (e) {
10341016
await Misc.processFailure(this);
10351017
throw e;
@@ -1068,16 +1050,13 @@ describe("MySQL REST Service", () => {
10681050
});
10691051

10701052
it("Get schema metadata", async () => {
1071-
await driver.wait(waitUntil.fetchIsSuccessful(`${baseUrl}/metadata-catalog`));
10721053
response = await fetch(`${baseUrl}/metadata-catalog`);
10731054
const data = await response.json();
10741055
expect(response.ok).to.be.true;
10751056
expect(data.items).to.exist;
10761057
});
10771058

10781059
it("Get object metadata", async () => {
1079-
await driver.wait(waitUntil
1080-
.fetchIsSuccessful(`${baseUrl}/metadata-catalog/${crudObject.restObjectPath.replace("/", "")}`));
10811060
response = await fetch(`${baseUrl}/metadata-catalog/${crudObject.restObjectPath.replace("/", "")}`);
10821061
const data = await response.json();
10831062
expect(response.ok).to.be.true;
@@ -1086,8 +1065,6 @@ describe("MySQL REST Service", () => {
10861065
});
10871066

10881067
it("Get object data", async () => {
1089-
await driver.wait(waitUntil
1090-
.fetchIsSuccessful(`${baseUrl}/${crudObject.restObjectPath.replace("/", "")}`));
10911068
response = await fetch(`${baseUrl}/${crudObject.restObjectPath.replace("/", "")}`);
10921069
const data = await response.json();
10931070
expect(response.ok).to.be.true;
@@ -1112,16 +1089,6 @@ describe("MySQL REST Service", () => {
11121089
});
11131090

11141091
it("Update table row", async () => {
1115-
await driver.wait(waitUntil.fetchIsSuccessful(`${baseUrl}/${crudObject.restObjectPath
1116-
.replace("/", "")}/${actorId}`, {
1117-
method: "put",
1118-
// eslint-disable-next-line @typescript-eslint/naming-convention
1119-
body: JSON
1120-
.stringify({ firstName: "Mister", lastName: "Test", lastUpdate: "2023-06-23 13:32:54" }),
1121-
// eslint-disable-next-line @typescript-eslint/naming-convention
1122-
headers: { "Content-Type": "application/json" },
1123-
}));
1124-
11251092
response = await fetch(`${baseUrl}/${crudObject.restObjectPath.replace("/", "")}/${actorId}`, {
11261093
method: "put",
11271094
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -1148,8 +1115,6 @@ describe("MySQL REST Service", () => {
11481115

11491116
it("Filter object data", async () => {
11501117
const query = `"firstName":"PENELOPE"`;
1151-
await driver.wait(waitUntil
1152-
.fetchIsSuccessful(`${baseUrl}/${crudObject.restObjectPath.replace("/", "")}?q={${query}}`));
11531118
response = await fetch(`${baseUrl}/${crudObject.restObjectPath.replace("/", "")}?q={${query}}`);
11541119
const data = await response.json();
11551120
expect(response.ok).to.be.true;

0 commit comments

Comments
 (0)