Skip to content

Commit

Permalink
feat(node): add os.loadavg() (denoland/deno#4075)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecyrbe authored and denobot committed Jan 31, 2021
1 parent 896ff29 commit 788cc00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
4 changes: 2 additions & 2 deletions node/os.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ export function hostname(): string {
return Deno.hostname();
}

/** Not yet implemented */
/** Returns an array containing the 1, 5, and 15 minute load averages */
export function loadavg(): number[] {
if (Deno.build.os == "win") {
return [0, 0, 0];
}
notImplemented(SEE_GITHUB_ISSUE);
return Deno.loadavg();
}

/** Not yet implemented */
Expand Down
29 changes: 6 additions & 23 deletions node/os_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
const { test } = Deno;
import {
assert,
assertThrows,
assertEquals,
AssertionError
} from "../testing/asserts.ts";
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import * as os from "./os.ts";

test({
Expand Down Expand Up @@ -168,26 +163,14 @@ test({
}
});

// Method is currently implemented correctly for windows but not for any other os
test({
name: "Load average is an array of 3 numbers",
fn() {
try {
const result = os.loadavg();
assert(result.length == 3);
assertEquals(typeof result[0], "number");
assertEquals(typeof result[1], "number");
assertEquals(typeof result[2], "number");
} catch (error) {
if (!(Object.getPrototypeOf(error) === Error.prototype)) {
const errMsg = `Unexpected error class: ${error.name}`;
throw new AssertionError(errMsg);
} else if (!error.message.includes("Not implemented")) {
throw new AssertionError(
"Expected this error to contain 'Not implemented'"
);
}
}
const result = os.loadavg();
assert(result.length == 3);
assertEquals(typeof result[0], "number");
assertEquals(typeof result[1], "number");
assertEquals(typeof result[2], "number");
}
});

Expand Down

0 comments on commit 788cc00

Please sign in to comment.