8000 Account for existing but empty `cpus` file by angelapwen · Pull Request #2151 · github/codeql-action · GitHub
[go: up one dir, main page]

Skip to content

Account for existing but empty cpus file #2151

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

Merged
merged 2 commits into from
Feb 20, 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
Prev Previous commit
Add unit tests for getCgroupCpuCountFromCpus
  • Loading branch information
angelapwen committed Feb 16, 2024
commit 8cb81db13519b2d9b9dc108c73658f3ba8008c51
3 changes: 2 additions & 1 deletion lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions lib/util.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.test.js.map

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,36 @@ for (const [
versionStub.restore();
});
}

test("getCgroupCpuCountFromCpus calculates the number of CPUs correctly", async (t) => {
await util.withTmpDir(async (tmpDir: string) => {
const testCpuFile = `${tmpDir}/cpus-file`;
fs.writeFileSync(testCpuFile, "1, 9-10\n", "utf-8");
t.deepEqual(
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
3,
);
});
});

test("getCgroupCpuCountFromCpus returns undefined if the CPU file doesn't exist", async (t) => {
await util.withTmpDir(async (tmpDir: string) => {
const testCpuFile = `${tmpDir}/cpus-file`;
t.false(fs.existsSync(testCpuFile));
t.deepEqual(
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
undefined,
);
});
});

test("getCgroupCpuCountFromCpus returns undefined if the CPU file exists but is empty", async (t) => {
await util.withTmpDir(async (tmpDir: string) => {
const testCpuFile = `${tmpDir}/cpus-file`;
fs.writeFileSync(testCpuFile, "\n", "utf-8");
t.deepEqual(
util.getCgroupCpuCountFromCpus(testCpuFile, getRunnerLogger(true)),
undefined,
);
});
});
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ function getCgroupCpuCountFromCpuMax(
/**
* Gets the number of available cores listed in the cgroup cpuset.cpus file at the given path.
*/
function getCgroupCpuCountFromCpus(
export function getCgroupCpuCountFromCpus(
cpusFile: string,
logger: Logger,
): number | undefined {
Expand Down
0