deno.land / std@0.166.0 / signal / test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { assert, assertEquals, assertThrows } from "../testing/asserts.ts";import { delay } from "../async/delay.ts";import { signal } from "./mod.ts";import { isWindows } from "../_util/os.ts";
Deno.test({ name: "signal() throws when called with empty signals", ignore: isWindows, fn() { assertThrows( () => { // deno-lint-ignore no-explicit-any (signal as any)(); }, Error, "No signals are given. You need to specify at least one signal to create a signal stream.", ); },});
Deno.test({ name: "signal() iterates for multiple signals", ignore: isWindows, fn: async () => { // This prevents the program from exiting. const t = setInterval(() => {}, 1000);
let c = 0; const sig = signal( "SIGUSR1", "SIGUSR2", "SIGINT", );
setTimeout(async () => { await delay(20); Deno.kill(Deno.pid, "SIGINT"); await delay(20); Deno.kill(Deno.pid, "SIGUSR2"); await delay(20); Deno.kill(Deno.pid, "SIGUSR1"); await delay(20); Deno.kill(Deno.pid, "SIGUSR2"); await delay(20); Deno.kill(Deno.pid, "SIGUSR1"); await delay(20); Deno.kill(Deno.pid, "SIGINT"); await delay(20); sig.dispose(); });
for await (const _ of sig) { c += 1; }
assertEquals(c, 6);
clearTimeout(t); },});
Deno.test({ name: "signal(), multiple .next() results don't resolve at the same time", ignore: isWindows, async fn() { // This prevents the program from exiting. const t = setInterval(() => {}, 1000); const sig = signal("SIGUSR1"); const sigIter = sig[Symbol.asyncIterator](); let done0 = false; let done1 = false; sigIter.next().then(() => { done0 = true; }); sigIter.next().then(() => { done1 = true; }); Deno.kill(Deno.pid, "SIGUSR1"); await delay(20); assert(done0); assert(!done1); Deno.kill(Deno.pid, "SIGUSR1"); await delay(20); assert(done0); assert(done1); sig.dispose(); clearTimeout(t); },});
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
2 months ago