##// END OF EJS Templates
Fixed substitution spec handling in log/ConsoleWriter
Fixed substitution spec handling in log/ConsoleWriter

File last commit:

r82:025f02eff3b2 v1.3.0 default
r85:ad9a66d0ebe4 v1.3.1 default
Show More
CancellationTests.ts
88 lines | 2.2 KiB | video/mp2t | TypeScriptLexer
/ src / test / ts / CancellationTests.ts
cin
tests moved under src/ folder...
r50 import { Cancellation } from "@implab/core/Cancellation";
cin
more tests
r77 import { delay } from "@implab/core/safe";
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 import { test } from "./TestTraits";
cin
tests moved under src/ folder...
r50
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 test("standalone cancellation", async t => {
cin
tests moved under src/ folder...
r50
let doCancel: (e) => void;
const ct = new Cancellation(cancel => {
doCancel = cancel;
});
let counter = 0;
const reason = "BILL";
t.true(ct.isSupported(), "Cancellation must be supported");
t.false(ct.isRequested(), "Cancellation shouldn't be requested");
ct.throwIfRequested();
t.pass("The exception shouldn't be thrown unless the cancellation is requested");
ct.register(() => counter++);
t.equals(counter, 0, "counter should be zero");
ct.register(() => counter++).destroy();
doCancel(reason);
t.true(ct.isRequested(), "Cancellation should be requested");
t.equals(counter, 1, "The registered callback should be triggered");
ct.register(() => counter++);
t.equals(counter, 2, "The callback should be triggered immediately");
let msg;
ct.register(e => msg = e);
t.equals(msg, reason, "The cancellation reason should be passed to callback");
try {
msg = null;
ct.throwIfRequested();
t.fail("The exception should be thrown");
} catch (e) {
msg = e;
}
t.equals(msg, reason, "The cancellation reason should be catched");
});
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 test("async cancellation", async t => {
cin
tests moved under src/ folder...
r50
const ct = new Cancellation(cancel => {
cancel("STOP!");
});
try {
await delay(0, ct);
t.fail("Should thow the exception");
} catch (e) {
t.equals(e, "STOP!", "Should throw the cancellation reason");
}
});
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 test("cancel with external event", async t => {
cin
tests moved under src/ folder...
r50 const ct = new Cancellation(cancel => {
setTimeout(x => cancel("STOP!"), 0);
});
try {
await delay(10000, ct);
t.fail("Should thow the exception");
} catch (e) {
t.equals(e, "STOP!", "Should throw the cancellation reason");
}
});
cin
StringBuilder, TextWriter, ConsoleWriter tests
r82 test("operation normal flow", async t => {
cin
tests moved under src/ folder...
r50
let htimeout;
const ct = new Cancellation(cancel => {
htimeout = setTimeout(() => cancel("STOP!"), 1000);
});
try {
await delay(0, ct);
t.pass("Should pass");
} finally {
clearTimeout(htimeout);
}
});