-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
aborter.test.ts
70 lines (60 loc) · 2.07 KB
/
aborter.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
import * as assert from "assert";
import { Aborter } from "../src/Aborter";
import { ContainerURL } from "../src/ContainerURL";
import { getBSU, getUniqueName } from "./utils";
import * as dotenv from "dotenv";
dotenv.config({path:"../.env"});
// tslint:disable:no-empty
describe("Aborter", () => {
const serviceURL = getBSU();
let containerName: string = getUniqueName("container");
let containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
beforeEach(async () => {
containerName = getUniqueName("container");
containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
});
it("should set value and get value successfully", async () => {
const aborter = Aborter.none.withValue("mykey", "myvalue");
assert.deepStrictEqual(aborter.getValue("mykey"), "myvalue");
});
it("Should not abort after calling abort()", async () => {
await containerURL.create(Aborter.none);
});
it("Should abort when calling abort() before request finishes", async () => {
const aborter = Aborter.none;
const response = containerURL.create(aborter);
aborter.abort();
try {
await response;
assert.fail();
} catch (err) {}
});
it("Should not abort when calling abort() after request finishes", async () => {
const aborter = Aborter.none;
await containerURL.create(aborter);
aborter.abort();
});
it("Should abort after aborter timeout", async () => {
try {
await containerURL.create(Aborter.timeout(1));
assert.fail();
} catch (err) {}
});
it("Should abort after father aborter calls abort()", async () => {
try {
const aborter = Aborter.none;
const response = containerURL.create(aborter.withTimeout(10 * 60 * 1000));
aborter.abort();
await response;
assert.fail();
} catch (err) {}
});
it("Should abort after father aborter timeout", async () => {
try {
const aborter = Aborter.timeout(1);
const response = containerURL.create(aborter.withTimeout(10 * 60 * 1000));
await response;
assert.fail();
} catch (err) {}
});
});