mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 07:34:36 +00:00
feat(node/os): implement getPriority, setPriority & userInfo (#19370)
Takes #4202 over Closes #17850 --------- Co-authored-by: ecyrbe <ecyrbe@gmail.com>
This commit is contained in:
parent
78ceeec6be
commit
aa8078b688
11 changed files with 314 additions and 31 deletions
|
@ -45,12 +45,14 @@ fn macos_shared_libraries() {
|
|||
// target/release/deno:
|
||||
// /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.255.0)
|
||||
// /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1228.0.0)
|
||||
// /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration (compatibility version 1.0.0, current version 1241.100.11)
|
||||
// /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60420.60.24)
|
||||
// /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
|
||||
// /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
|
||||
const EXPECTED: [&str; 6] =
|
||||
const EXPECTED: [&str; 7] =
|
||||
["/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation",
|
||||
"/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices",
|
||||
"/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration",
|
||||
"/System/Library/Frameworks/Security.framework/Versions/A/Security",
|
||||
"/usr/lib/libiconv.2.dylib",
|
||||
"/usr/lib/libSystem.B.dylib",
|
||||
|
|
|
@ -5,6 +5,7 @@ import os from "node:os";
|
|||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertNotEquals,
|
||||
assertThrows,
|
||||
} from "../../../test_util/std/testing/asserts.ts";
|
||||
|
||||
|
@ -252,28 +253,39 @@ Deno.test({
|
|||
});
|
||||
|
||||
Deno.test({
|
||||
name: "APIs not yet implemented",
|
||||
name: "os.setPriority() & os.getPriority()",
|
||||
// disabled because os.getPriority() doesn't work without sudo
|
||||
ignore: true,
|
||||
fn() {
|
||||
assertThrows(
|
||||
() => {
|
||||
os.getPriority();
|
||||
},
|
||||
Error,
|
||||
"Not implemented",
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
os.setPriority(0);
|
||||
},
|
||||
Error,
|
||||
"Not implemented",
|
||||
);
|
||||
assertThrows(
|
||||
() => {
|
||||
os.userInfo();
|
||||
},
|
||||
Error,
|
||||
"Not implemented",
|
||||
const child = new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "while (true) { console.log('foo') }"],
|
||||
}).spawn();
|
||||
const originalPriority = os.getPriority(child.pid);
|
||||
assertNotEquals(originalPriority, os.constants.priority.PRIORITY_HIGH);
|
||||
os.setPriority(child.pid, os.constants.priority.PRIORITY_HIGH);
|
||||
assertEquals(
|
||||
os.getPriority(child.pid),
|
||||
os.constants.priority.PRIORITY_HIGH,
|
||||
);
|
||||
os.setPriority(child.pid, originalPriority);
|
||||
assertEquals(os.getPriority(child.pid), originalPriority);
|
||||
child.kill();
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name:
|
||||
"os.setPriority() throw os permission denied error & os.getPriority() doesn't",
|
||||
async fn() {
|
||||
const child = new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "while (true) { console.log('foo') }"],
|
||||
}).spawn();
|
||||
assertThrows(
|
||||
() => os.setPriority(child.pid, os.constants.priority.PRIORITY_HIGH),
|
||||
Deno.errors.PermissionDenied,
|
||||
);
|
||||
os.getPriority(child.pid);
|
||||
child.kill();
|
||||
await child.status;
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue