Skip to content

Commit a411517

Browse files
author
Anna Antonenko
committed
feat: flush() on Write and Duplex
1 parent 7c53908 commit a411517

15 files changed

+169
-132
lines changed

.eslintrc.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,11 @@
2323
"dot-location": ["error", "property"],
2424
"handle-callback-err": "off",
2525
"indent": ["error", 4],
26-
"keyword-spacing": ["error", { "overrides": {
27-
"if": { "after": false },
28-
"for": { "after": false },
29-
"while": { "after": false },
30-
"catch": { "after": false }
31-
}}],
26+
"keyword-spacing": "off",
3227
"max-nested-callbacks": ["error", { "max": 4 }],
3328
"max-statements-per-line": ["error", { "max": 2 }],
3429
"no-console": "off",
30+
"no-empty": "off",
3531
"no-empty-function": "off",
3632
"no-floating-decimal": "error",
3733
"no-lonely-if": "error",
@@ -64,6 +60,7 @@
6460
"@typescript-eslint/require-await": "off",
6561
"@typescript-eslint/no-unsafe-assignment": "off",
6662
"@typescript-eslint/no-unsafe-call": "off",
67-
"@typescript-eslint/no-non-null-assertion": "off"
63+
"@typescript-eslint/no-non-null-assertion": "off",
64+
"@typescript-eslint/no-empty-function": "off"
6865
}
6966
}

__tests__/certs/server.cert

Lines changed: 0 additions & 21 deletions
This file was deleted.

__tests__/certs/server.key

Lines changed: 0 additions & 28 deletions
This file was deleted.

__tests__/fieldArr.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe("Field arrays", () => {
2828

2929
for(const val of values) {
3030
await repr.write(a, val);
31+
await a.flush();
3132
const value = await repr.read(b);
3233
expect(value).toEqual(val);
3334
}
@@ -50,6 +51,7 @@ describe("Field arrays", () => {
5051

5152
for(const [pass, val] of values) {
5253
await repr.write(a, val);
54+
await a.flush();
5355
const value = await repr.read(b);
5456
expect(value).toEqual(val);
5557
expect(repr.findError(value) === null).toEqual(pass);
@@ -72,6 +74,7 @@ describe("Field arrays", () => {
7274

7375
for(const val of values) {
7476
await repr.write(a, val);
77+
await a.flush();
7578
const value = await repr.read(b);
7679

7780
expect(value).toEqual(val);
@@ -95,6 +98,7 @@ describe("Field arrays", () => {
9598

9699
for(const val of values) {
97100
await repr.write(a, val);
101+
await a.flush();
98102
const value = await repr.read(b);
99103

100104
expect(value).toEqual(val);
@@ -112,6 +116,7 @@ describe("Field arrays", () => {
112116

113117
repr.setMode([true, false]);
114118
await a.write(Buffer.from([123, 123]));
119+
await a.flush();
115120
try {
116121
await repr.read(b);
117122
fail("Expected error");
@@ -121,6 +126,7 @@ describe("Field arrays", () => {
121126

122127
repr.setMode([true, true]);
123128
await a.write(Buffer.from([0x40, 123]));
129+
await a.flush();
124130
try {
125131
await repr.read(b);
126132
fail("Expected error");

__tests__/perf.spec.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

__tests__/plu.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe("Partial list updates", () => {
1212
Object.assign(expected, { partial: "append", count: 2 });
1313

1414
await repr.write(a, arr);
15+
await a.flush();
1516
expect(await repr.read(b)).toEqual(expected);
1617
});
1718

@@ -23,6 +24,7 @@ describe("Partial list updates", () => {
2324
Object.assign(expected, { partial: "prepend", count: 2 });
2425

2526
await repr.write(a, arr);
27+
await a.flush();
2628
expect(await repr.read(b)).toEqual(expected);
2729
});
2830

@@ -34,6 +36,7 @@ describe("Partial list updates", () => {
3436
Object.assign(expected, { partial: "insert", index: 1, count: 2 });
3537

3638
await repr.write(a, arr);
39+
await a.flush();
3740
expect(await repr.read(b)).toEqual(expected);
3841
});
3942

@@ -45,6 +48,7 @@ describe("Partial list updates", () => {
4548
Object.assign(expected, { partial: "remove", index: 1, count: 2 });
4649

4750
await repr.write(a, arr);
51+
await a.flush();
4852
expect(await repr.read(b)).toEqual(expected);
4953
});
5054
});

__tests__/repr.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe("Atomic data type representation", () => {
99
const values = [0, 1, 123, 255];
1010
for(const val of values) {
1111
await repr.write(a, val);
12+
await a.flush();
1213
expect(await repr.read(b)).toEqual(val);
1314
}
1415
});
@@ -20,6 +21,7 @@ describe("Atomic data type representation", () => {
2021
const values = [0, 1, 123, 255, 256, 10000, 65535, 65536, 10000000];
2122
for(const val of values) {
2223
await repr.write(a, val);
24+
await a.flush();
2325
expect(await repr.read(b)).toEqual(val);
2426
}
2527
});
@@ -35,6 +37,7 @@ describe("Atomic data type representation", () => {
3537
];
3638
for(const val of values) {
3739
await repr.write(a, val);
40+
await a.flush();
3841
expect(await repr.read(b)).toEqual(val);
3942
}
4043
});
@@ -56,6 +59,7 @@ describe("Atomic data type representation", () => {
5659
];
5760
for(const val of values) {
5861
await repr.write(a, val);
62+
await a.flush();
5963
expect(await repr.read(b)).toEqual(val);
6064
}
6165

@@ -83,6 +87,7 @@ describe("Atomic data type representation", () => {
8387
];
8488
for(const val of values) {
8589
await repr.write(a, val);
90+
await a.flush();
8691
expect(await repr.read(b)).toEqual(val);
8792
}
8893

@@ -97,6 +102,7 @@ describe("Atomic data type representation", () => {
97102
const values = ["hi", "hello world", "aboba", "speedapi", "i like turtles"];
98103
for(const val of values) {
99104
await repr.write(a, val);
105+
await a.flush();
100106
expect(await repr.read(b)).toEqual(val);
101107
}
102108
});
@@ -108,13 +114,16 @@ describe("Atomic data type representation", () => {
108114
const values = [false, true];
109115
for(const val of values) {
110116
await repr.write(a, val);
117+
await a.flush();
111118
expect(await repr.read(b)).toEqual(val);
112119
}
113120

114121
// test truthy values other than "1"
115122
await a.write(Buffer.from([2]));
123+
await a.flush();
116124
expect(await repr.read(b)).toEqual(true);
117125
await a.write(Buffer.from([100]));
126+
await a.flush();
118127
expect(await repr.read(b)).toEqual(true);
119128
});
120129

@@ -131,6 +140,7 @@ describe("Atomic data type representation", () => {
131140
];
132141
for(const val of values) {
133142
await repr.write(a, val);
143+
await a.flush();
134144
expect(await repr.read(b)).toEqual(val);
135145
}
136146
});
@@ -148,6 +158,7 @@ describe("Atomic data type representation", () => {
148158
];
149159
for(const val of values) {
150160
await repr.write(a, val);
161+
await a.flush();
151162
expect(await repr.read(b)).toEqual(val);
152163
}
153164
});

__tests__/serverApi.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe("Nice server API", () => {
8484
niceServer.debug = true;
8585

8686
await clientSession.Test.staticEcho({ str: "Hello" });
87-
expect(console.log).toHaveBeenCalledTimes(4);
87+
expect(console.log).toHaveBeenCalledTimes(8);
8888

8989
niceServer.debug = false;
9090
});

__tests__/transport.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as speedapi from "../src/index";
2+
import * as node from "../src/transport/node";
3+
import * as api from "./entity_output/ts/index";
4+
5+
describe("Transport layer", () => {
6+
test("Built-in Node transport crash", () => {
7+
try {
8+
new node.TlsClient(api.$specSpace, {});
9+
fail("should crash");
10+
} catch { }
11+
try {
12+
new node.TlsServer(api.$specSpace, {});
13+
fail("should crash");
14+
} catch { }
15+
try {
16+
new node.TlsListener(api.$specSpace, {}, undefined);
17+
fail("should crash");
18+
} catch { }
19+
});
20+
21+
test("Flush after segment write", async () => {
22+
class TestLink extends speedapi.Duplex {
23+
flushed = false;
24+
25+
async close() { }
26+
async write() { }
27+
async read(_n: number) { return Uint8Array.from([]); }
28+
override async flush() {
29+
this.flushed = true;
30+
}
31+
}
32+
33+
const link = new TestLink();
34+
expect(link.flushed).toBe(false);
35+
36+
// sending the segment manually because `session.global_echo` awaits a response
37+
const method = new api.GlobalEcho();
38+
method.params = { str: "hi" };
39+
await new speedapi.segment.InvokeMethodSegment(0, method).write(link);
40+
41+
expect(link.flushed).toBe(true);
42+
});
43+
});

0 commit comments

Comments
 (0)