Skip to content

Commit

Permalink
tc
Browse files Browse the repository at this point in the history
  • Loading branch information
clee2000 committed Oct 24, 2024
1 parent 837e72a commit cbda16e
Show file tree
Hide file tree
Showing 8 changed files with 1,238 additions and 1,392 deletions.
1 change: 1 addition & 0 deletions torchci/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const customJestConfig = {
"@opensearch-project/opensearch/aws":
"@opensearch-project/opensearch/lib/aws/index.js",
},
setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
};

module.exports = createJestConfig(customJestConfig);
2 changes: 1 addition & 1 deletion torchci/lib/useGroupingPreference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function usePreference(
// Gets around hydration errors?
useEffect(() => {
setState(initialVal);
}, []);
}, [initialVal]);

return [state, setStatePersist];
}
Expand Down
2 changes: 1 addition & 1 deletion torchci/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
11 changes: 6 additions & 5 deletions torchci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
"lodash": "^4.17.21",
"minimatch": "^9.0.3",
"minimist": "^1.2.6",
"next": "12.1.5",
"next": "14.2.16",
"next-auth": "^4.24.5",
"octokit": "^1.7.1",
"probot": "^12.3.3",
"react": "18.0.0",
"react-dom": "18.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-ga4": "^2.1.0",
"react-icons": "^4.3.1",
"react-linkify-it": "1.0.7",
Expand All @@ -64,7 +64,7 @@
"devDependencies": {
"@types/argparse": "^2.0.10",
"@types/echarts": "^4.9.14",
"@types/jest": "^27.4.1",
"@types/jest": "^29.5.14",
"@types/jsdom": "^16.2.14",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.40",
Expand All @@ -77,11 +77,12 @@
"dotenv": "^16.0.0",
"eslint": "8.13.0",
"eslint-config-next": "12.1.5",
"jest": "^27.5.0",
"jest": "^29.7.0",
"monaco-editor": "^0.33.0",
"nock": "^13.2.6",
"prettier": "2.6.2",
"prettier-plugin-organize-imports": "^3.2.4",
"ts-jest": "^29.2.5",
"typescript": "4.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default async function handler(
}

const { repoOwner, repoName, annotation } = req.query;
const repoOwnerStr = Array.isArray(repoOwner) ? repoOwner[0] : repoOwner;
const repoNameStr = Array.isArray(repoName) ? repoName[0] : repoName;
const repoOwnerStr = Array.isArray(repoOwner) ? repoOwner[0] : repoOwner!;
const repoNameStr = Array.isArray(repoName) ? repoName[0] : repoName!;
const octokit = await getOctokit(repoOwnerStr, repoNameStr);
const user = await octokit.rest.users.getAuthenticated();
const hasPermission = hasWritePermissionsUsingOctokit(
Expand Down
96 changes: 31 additions & 65 deletions torchci/test/retryBot.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as jobUtils from "lib/jobUtils";
import nock from "nock";
import { Probot } from "probot";
import myProbotApp from "../lib/bot/retryBot";
Expand All @@ -12,6 +13,9 @@ describe("retry-bot", () => {
beforeEach(() => {
probot = utils.testProbot();
probot.load(myProbotApp);
nock("https://api.github.com")
.post("/app/installations/2/access_tokens")
.reply(200, { token: "test" });
});

afterEach(() => {
Expand All @@ -24,6 +28,9 @@ describe("retry-bot", () => {
event.payload.workflow_run.name = "pull";
const workflow_jobs = requireDeepCopy("./fixtures/workflow_jobs.json");
workflow_jobs.jobs[0].conclusion = "failure";
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([]);

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
Expand All @@ -49,23 +56,19 @@ describe("retry-bot", () => {
'{retryable_workflows: ["pull", "trunk", "linux-binary", "windows-binary"]}'
);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
const rockset = nock("https://api.rs2.usw2.rockset.com")
.persist()
.post((url) => true)
.reply(200, { results: [] });

await probot.receive(event);

handleScope(scope);
handleScope(rockset);
});

test("rerun when workflow name starts with a valid prefix", async () => {
const event = requireDeepCopy("./fixtures/workflow_run.completed.json");
event.payload.workflow_run.name = "linux-binary-manywheel";
const workflow_jobs = requireDeepCopy("./fixtures/workflow_jobs.json");
workflow_jobs.jobs[0].conclusion = "failure";
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([]);

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
Expand All @@ -91,16 +94,9 @@ describe("retry-bot", () => {
'{retryable_workflows: ["pull", "trunk", "linux-binary", "windows-binary"]}'
);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
const rockset = nock("https://api.rs2.usw2.rockset.com")
.persist()
.post((uri) => true)
.reply(200, { results: [] });

await probot.receive(event);

handleScope(scope);
handleScope(rockset);
});

test("dont rerun if failed at test step", async () => {
Expand All @@ -110,6 +106,9 @@ describe("retry-bot", () => {
workflow_jobs.jobs[0].conclusion = "failure";
workflow_jobs.jobs[4].conclusion = "failure";
workflow_jobs.jobs[4].steps[0].conclusion = "failure";
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([]);

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
Expand All @@ -135,16 +134,9 @@ describe("retry-bot", () => {
)
.reply(200);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
const rockset = nock("https://api.rs2.usw2.rockset.com")
.persist()
.post((uri) => true)
.reply(200, { results: [] });

await probot.receive(event);

handleScope(scope);
handleScope(rockset);
});

test("dont rerun unstable jobs", async () => {
Expand All @@ -154,6 +146,9 @@ describe("retry-bot", () => {
workflow_jobs.jobs[4].name = `${workflow_jobs.jobs[0].name} (unstable)`;
workflow_jobs.jobs[4].conclusion = "failure";
workflow_jobs.jobs[4].steps[0].conclusion = "failure";
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([]);

const owner = event.payload.repository.owner.login;
const repo = event.payload.repository.name;
Expand All @@ -175,16 +170,9 @@ describe("retry-bot", () => {
'{retryable_workflows: ["pull", "trunk", "linux-binary", "windows-binary"]}'
);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
const rockset = nock("https://api.rs2.usw2.rockset.com")
.persist()
.post((uri) => true)
.reply(200, { results: [] });

await probot.receive(event);

handleScope(scope);
handleScope(rockset);
});

test("rerun previous workflow if it has more than one flaky jobs in trunk", async () => {
Expand All @@ -200,7 +188,11 @@ describe("retry-bot", () => {
const attempt_number = event.payload.workflow_run.run_attempt;
const run_id = event.payload.workflow_run.id;
const prev_run_id = 1;

// 2 out of 3 previous jobs are flaky
jest.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow").mockResolvedValue([
{ workflow_id: prev_run_id, job_id: 1 },
{ workflow_id: prev_run_id, job_id: 3 },
]);
const scope = nock("https://api.github.com")
.get(
`/repos/${owner}/${repo}/actions/runs/${run_id}/attempts/${attempt_number}/jobs?page=1&per_page=100`
Expand All @@ -224,20 +216,8 @@ describe("retry-bot", () => {
)
.reply(200);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
// 2 out of 3 previous jobs are flaky
const rockset = nock("https://api.rs2.usw2.rockset.com")
.post((uri) => true)
.reply(200, {
results: [
{ workflow_id: prev_run_id, job_id: 1 },
{ workflow_id: prev_run_id, job_id: 3 },
],
});

await probot.receive(event);

handleScope(rockset);
handleScope(scope);
});

Expand All @@ -255,7 +235,10 @@ describe("retry-bot", () => {
const run_id = event.payload.workflow_run.id;
const prev_run_id = 1;
const prev_job_id = 1;

jest.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow").mockResolvedValue([
{ workflow_id: prev_run_id, job_id: 1 },
{ workflow_id: prev_run_id, job_id: 3 },
]);
const scope = nock("https://api.github.com")
.get(
`/repos/${owner}/${repo}/actions/runs/${run_id}/attempts/${attempt_number}/jobs?page=1&per_page=100`
Expand All @@ -279,17 +262,8 @@ describe("retry-bot", () => {
)
.reply(200);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
// Only the first job are flaky
const rockset = nock("https://api.rs2.usw2.rockset.com")
.post((uri) => true)
.reply(200, {
results: [{ workflow_id: prev_run_id, job_id: prev_job_id }],
});

await probot.receive(event);

handleScope(rockset);
handleScope(scope);
});

Expand Down Expand Up @@ -324,18 +298,13 @@ describe("retry-bot", () => {
`/repos/${owner}/${repo}/actions/runs/${prev_run_id}/rerun-failed-jobs`
) // Retry previous workflow
.reply(200);

process.env.ROCKSET_API_KEY = "random key doesnt matter";
// Only the first job are flaky
const rockset = nock("https://api.rs2.usw2.rockset.com")
.post((uri) => true)
.reply(200, {
results: [{ workflow_id: prev_run_id, job_id: prev_job_id }],
});
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([{ workflow_id: prev_run_id, job_id: prev_job_id }]);

await probot.receive(event);

handleScope(rockset);
handleScope(scope);
});

Expand Down Expand Up @@ -401,16 +370,13 @@ describe("retry-bot", () => {

process.env.ROCKSET_API_KEY = "random key doesnt matter";
// Only the first job are flaky
const rockset = nock("https://api.rs2.usw2.rockset.com")
.post((uri) => true)
.reply(200, {
results: [],
});
jest
.spyOn(jobUtils, "getFlakyJobsFromPreviousWorkflow")
.mockResolvedValue([]);

await probot.receive(event);

handleScope(scope);
handleScope(rockset);
});

test("dont re-run unless retryable_workflows is specified in .github/pytorch-probot.yml", async () => {
Expand Down
18 changes: 18 additions & 0 deletions torchci/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Taken from https://stackoverflow.com/a/77157708 to get around errors like
// `TypeError: Cannot redefine property: searchSimilarFailures` when using
// jest.spyOn when upgrading to node 14.2.16.
// The following Object.defineProperty wrapper will ensure that all esModule exports
// are configurable and can be mocked by Jest.
const objectDefineProperty = Object.defineProperty;
Object.defineProperty = function <T>(
obj: T,
propertyName: PropertyKey,
attributes: PropertyDescriptor & ThisType<any>
): T {
if ((obj as { __esModule?: true })["__esModule"]) {
attributes = { ...attributes, configurable: true };
}
return objectDefineProperty(obj, propertyName, attributes);
};

export {};
Loading

0 comments on commit cbda16e

Please sign in to comment.