stop getting logs on test timeout

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2021-02-02 10:37:16 -05:00
1 parent 624b7b50ee
commit 401908f4e5
16 files changed
+4152 -37

No files matched your search

+19 -2
View File
@@ -3,15 +3,23 @@ import * as utils from "../helpers/utils";
import { listHelmRepositories } from "../helpers/utils";
import { fail } from "assert";
import open from "open";
import { AbortController } from "abort-controller";
jest.setTimeout(60000);
// FIXME (!): improve / simplify all css-selectors + use [data-test-id="some-id"] (already used in some tests below)
describe("Lens integration tests", () => {
let app: Application;
let abortContoller: AbortController;
describe("app start", () => {
beforeAll(async () => app = await utils.appStart(), 20000);
beforeAll(async () => {
app = await utils.appStart();
}, 20000);
beforeEach(() => {
abortContoller = new AbortController();
});
afterAll(async () => {
if (app?.isRunning()) {
@@ -19,6 +27,10 @@ describe("Lens integration tests", () => {
}
});
afterEach(() => {
abortContoller.abort();
});
it('shows "whats new"', async () => {
await utils.clickWhatsNew(app);
});
@@ -32,11 +44,16 @@ describe("Lens integration tests", () => {
it("should handle opening lens:// links", async () => {
await open("lens://app/foobar");
await utils.waitForLogsToContain(app, {
await utils.waitForLogsToContain(app, abortContoller, {
main: ["No handler", "lens://app/foobar"],
renderer: ["No handler", "lens://app/foobar"],
});
});
it("should opening lens://app/preferences", async () => {
await open("lens://app/preferences");
await app.client.waitUntilTextExists("h2", "Preferences");
});
});
describe("preferences page", () => {
+16 -13
View File
@@ -9,6 +9,8 @@ import * as utils from "../helpers/utils";
import { addMinikubeCluster, minikubeReady, waitForMinikubeDashboard } from "../helpers/minikube";
import { exec } from "child_process";
import * as util from "util";
import { delay } from "../../src/common/utils";
import { AbortController } from "abort-controller";
export const promiseExec = util.promisify(exec);
@@ -337,12 +339,19 @@ describe("Lens cluster pages", () => {
});
describe("viewing pod logs", () => {
beforeEach(appStartAddCluster, 40000);
let abortContoller: AbortController;
beforeEach(async () => {
await appStartAddCluster();
abortContoller = new AbortController();
}, 40000);
afterEach(async () => {
if (app && app.isRunning()) {
return utils.tearDown(app);
if (app?.isRunning()) {
await utils.tearDown(app);
}
abortContoller.abort();
});
it(`shows a logs for a pod`, async () => {
@@ -355,19 +364,13 @@ describe("Lens cluster pages", () => {
await app.client.keys("kube-system");
await app.client.keys("Enter");// "\uE007"
await app.client.waitUntilTextExists("div.TableCell", "kube-apiserver");
let podMenuItemEnabled = false;
// Wait until extensions are enabled on renderer
while (!podMenuItemEnabled) {
const logs = await app.client.getRenderProcessLogs();
await utils.waitForLogsToContain(app, abortContoller, {
renderer: ["[EXTENSION]: enabled lens-pod-menu@"],
});
podMenuItemEnabled = !!logs.find(entry => entry.message.includes("[EXTENSION]: enabled lens-pod-menu@"));
await delay(500); // Give some extra time to prepare extensions
if (!podMenuItemEnabled) {
await new Promise(r => setTimeout(r, 1000));
}
}
await new Promise(r => setTimeout(r, 500)); // Give some extra time to prepare extensions
// Open logs tab in dock
await app.client.click(".list .TableRow:first-child");
await app.client.waitForVisible(".Drawer");
+8 -9
View File
@@ -5,13 +5,14 @@ import fse, { writeFile } from "fs-extra";
import path from "path";
import os from "os";
import { delay } from "../../src/common/utils";
import { AbortController } from "abort-controller";
interface AppTestingPaths {
testingPath: string,
libraryPath: string,
}
export function getAppTestingPaths(): AppTestingPaths {
function getAppTestingPaths(): AppTestingPaths {
switch (process.platform) {
case "win32":
return {
@@ -62,7 +63,7 @@ export const keys = {
};
export async function appStart() {
const app = setup();
const app = new Application(setup());
await app.start();
// Wait for splash screen to be closed
@@ -149,15 +150,13 @@ interface LogLines {
main: string[];
}
async function* splitLogs(app: Application): AsyncGenerator<LogLines, void, void> {
async function* splitLogs(app: Application, signal: AbortController): AsyncGenerator<LogLines, void, void> {
let lastLogLineCount = 0;
for(;;) { // infinite loop
while (!signal.signal.aborted) { // infinite loop
const curLogs: string[] = (app as any).chromeDriver.getLogs();
const newLogs = curLogs.slice(lastLogLineCount);
console.log(curLogs);
lastLogLineCount = curLogs.length;
const item: LogLines = {
@@ -176,7 +175,7 @@ async function* splitLogs(app: Application): AsyncGenerator<LogLines, void, void
}
yield item;
await delay(500); // only delay after the first attempt
await delay(500, signal); // only delay after the first attempt and fail fast if the signal has occured
}
}
@@ -190,13 +189,13 @@ async function* splitLogs(app: Application): AsyncGenerator<LogLines, void, void
* @param source Whether to wait for renderer or main logs
* @param values The list of strings that should all be contained in the logs
*/
export async function waitForLogsToContain(app: Application, matches: LogMatches): Promise<void> {
export async function waitForLogsToContain(app: Application, signal: AbortController, matches: LogMatches): Promise<void> {
const notYetFound = {
main: new Set(matches.main ?? []),
renderer: new Set(matches.renderer ?? []),
};
for await (const logs of splitLogs(app)) {
for await (const logs of splitLogs(app, signal)) {
mainMatch: for (const logPart of notYetFound.main) {
for (const logLine of logs.main) {
if (logLine.includes(logPart)) {