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

feat: add reset pod #454

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions scripts/test.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const contextPatch = [
command: "Nocalhost.applyKubernetesObject",
when: "viewItem =~ /^application-(.*)-installed/i",
},
{
command: "Nocalhost.reset",
when:
"viewItem =~ /^workload-(deployment|statefulSet|job|daemonSet|cronjob|pod|crd-resources)-dev-(?!vpn_)/i",
},
];
packageJson.contributes.menus["view/item/context"].forEach((context) => {
if (
Expand Down
6 changes: 0 additions & 6 deletions test/extension/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@ const getUserDataDir = async () => {
}

await fse.copy(path.join(__dirname, "./config/vscode"), userDataDir);

// copy test config file
await fse.copy(
path.join(__dirname, "./config/yaml"),
path.join(os.tmpdir(), "./config/yaml")
);
return userDataDir;
};

Expand Down
2 changes: 1 addition & 1 deletion test/extension/integration/applyManifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const applyDeployment = async () => {
".action-label[title='Apply New Manifest']"
);
await applyNode.click();
await file.selectPath(path.join(os.tmpdir(), "./config/yaml"));
await file.selectPath(path.join(__dirname, "../config/yaml"));

return waitForMessage("Resource(Deployment) php created", 60 * 1000);
};
Expand Down
55 changes: 55 additions & 0 deletions test/extension/integration/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const { viewLogTests } = require("./viewLog.test");
const { editConfigTests } = require("./editConfig.test");
const { remoteRunTests } = require("./remoteRun.test");
const { applyManifestTests } = require("./applyManifest.test");
const { resetPodTests } = require("./resetPod.test");
let fpsArr = [];

const screenshotPath = path.join(__dirname, "../../../.screenshot");

Expand All @@ -33,6 +35,43 @@ afterEach(async () => {
});
});

beforeAll(async () => {
await page.tracing.start({
path: `${screenshotPath}/.trace.json`,
screenshots: true,
screenshotPath: screenshotPath,
});

// calc fps
await page.evaluate(async () => {
let lastTime = (window.performance || window.Date).now();
let fpsCount = 0;
let fps = 0;
let arr = [];
const fpsInterval = 30;

const getFps = () => {
fpsCount++;
const timeNow = (window.performance || window.Date).now();
if (fpsCount >= fpsInterval) {
fps = Math.round((1000 * fpsCount) / (timeNow - lastTime));
lastTime = timeNow;
fpsCount = 0;
// const memory = window.performance.memory;
arr.push({ fps });
}
};

const start = () => {
getFps();
window.__data = JSON.stringify(arr);
window.requestAnimationFrame(start);
};

start();
});
});

describe("nhctl", nhctlTests);
describe("connect", connectTests);
describe("install", installTests);
Expand All @@ -43,6 +82,22 @@ describe("editConfig", editConfigTests);
// remote run after edit config hotreload
describe("remoteRun", remoteRunTests);
describe("applyManifest", applyManifestTests);
describe("resetPod", resetPodTests);

afterAll(async () => {
const fps = await page.evaluate(() => {
return window.__data;
});
logger.info(`fps: ${fps}`);
await (() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 2000);
});
})();
await page.tracing.stop();
});

module.exports = {
screenshotPath,
Expand Down
1 change: 0 additions & 1 deletion test/extension/integration/portForward.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ async function checkReady() {

async function add() {
const treeItem = await tree.getItem(...treeItemPath);

const portForward = await treeItem.$(".action-label[title='Port Forward']");
await portForward.click();

Expand Down
43 changes: 43 additions & 0 deletions test/extension/integration/resetPod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { performance, PerformanceObserver } = require("perf_hooks");
const { tree } = require("../lib/components");
const { waitForMessage } = require("./index");
const logger = require("../lib/log");

const treeItemPath = [
"",
"default",
"bookinfo",
"Workloads",
"Deployments",
"ratings",
];

const resetPod = async () => {
// add performance mark
/* * /
const obs = new PerformanceObserver((items) => {
const entry = items.getEntries()[0];
logger.info(entry.duration);
performance.clearMarks();
obs.disconnect();
});
obs.observe({ entryTypes: ["measure"] });
// performance.measure("Start to Now");
performance.mark("tree-start-time");

performance.mark("tree-end-time");
performance.measure("tree-time", {
start: "tree-start-time",
end: "tree-end-time",
});
/** */
const ratings = await tree.getItem(...treeItemPath);
const resetNode = await ratings.$(".action-label[title='Reset Pod']");

await resetNode.click();
return waitForMessage("reset service ratings", 60 * 1000);
};

module.exports = {
resetPod,
};
14 changes: 14 additions & 0 deletions test/extension/integration/resetPod.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { checkReady } = require("./portForward");
const { resetPod } = require("./resetPod");

const resetPodTests = () => {
beforeAll(async (done) => {
checkReady().then(done).catch(done.fail);
});

it("reset pod", resetPod);
};

module.exports = {
resetPodTests,
};
2 changes: 1 addition & 1 deletion test/extension/lib/components/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function selectPath(path) {
await input.type(" ");
await page.keyboard.press("Backspace");

await page.waitForTimeout(1_00);
await page.waitForTimeout(1_000);

const action = await page.waitForSelector(
".quick-input-widget .quick-input-action a"
Expand Down