@torrent-tv/proxy 2.80.18 → 2.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/docs/encode-architecture.md +51 -2
- package/package.json +1 -1
- package/research/double-spawn-2026-09-10.md +171 -0
- package/services/disk/DiskSpace.js +146 -0
- package/services/disk/wire.js +60 -0
- package/services/encode/EncodeRun.js +37 -9
- package/services/encode/SegmentStore.js +284 -232
- package/services/encode/run-command.js +16 -1
- package/services/hls-session-manager.js +31 -128
- package/services/orchestrators/EncodeOrchestrator.js +52 -38
- package/services/piece-store/allowance.js +107 -0
- package/services/piece-store/piece-disk-store.js +365 -0
- package/services/piece-store/shared-piece-store.js +1549 -1535
- package/services/segment-formats/fmp4.js +54 -0
- package/services/segment-formats/mpegts.js +54 -0
- package/services/torrent-worker/client.js +32 -0
- package/services/torrent-worker/pool-adapter.js +15 -0
- package/services/torrent-worker/protocol.js +9 -0
- package/services/torrent-worker/worker.js +8 -1
- package/services/viewer/positions.js +48 -0
- package/test/audio-inventory.test.js +176 -176
- package/test/auto-quality-step.test.js +514 -514
- package/test/concurrent-cost.test.js +138 -138
- package/test/coverage-follows-the-disk.test.js +191 -187
- package/test/coverage-map.test.js +195 -195
- package/test/declared-tracks.test.js +35 -35
- package/test/disk-space.test.js +138 -0
- package/test/encode-orchestrator.test.js +0 -3
- package/test/encode-run.test.js +5 -12
- package/test/held-request-width.test.js +155 -155
- package/test/helpers/encode-run.js +2 -2
- package/test/matroska-blocks.test.js +0 -0
- package/test/matroska-cues-track.test.js +192 -192
- package/test/mp4-composition-times.test.js +0 -0
- package/test/mp4-subtitles.test.js +173 -173
- package/test/one-authority.test.js +281 -220
- package/test/orchestrator-wired.test.js +199 -195
- package/test/packet-witness-ring.test.js +236 -236
- package/test/packet-witness.test.js +148 -148
- package/test/piece-disk-store.test.js +267 -0
- package/test/piece-reader.test.js +4 -4
- package/test/piece-store-eviction.test.js +17 -17
- package/test/piece-store-reservations.test.js +20 -1
- package/test/piece-store-slow-disk.test.js +16 -1
- package/test/produced-copy-choice.test.js +258 -358
- package/test/read-window.test.js +6 -6
- package/test/run-intervals.test.js +100 -100
- package/test/seek-landing.test.js +109 -109
- package/test/segment-serve-wiring.test.js +8 -9
- package/test/segment-store-eviction.test.js +232 -0
- package/test/segment-store.test.js +238 -216
- package/test/segments-are-shared.test.js +1 -1
- package/test/shared-piece-store.test.js +12 -12
- package/test/sidecar-naming.test.js +142 -142
- package/test/subtitle-cue-framing.test.js +200 -200
- package/test/subtitle-cue-walk.test.js +369 -369
- package/test/subtitle-defaults.test.js +97 -97
- package/test/subtitle-track-numbering.test.js +370 -370
- package/test/tail-duplication.test.js +167 -167
- package/test/tracks-begin-together.test.js +195 -195
- package/test/two-viewers-one-picture.test.js +374 -374
- package/test/video-facts.test.js +102 -102
- package/test/wedge-certainty.test.js +131 -131
- package/services/encode/open-piece.js +0 -135
- package/services/piece-store/disk-tier.js +0 -151
- package/test/open-piece.test.js +0 -152
|
@@ -1,216 +1,238 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file One store of segments, addressed by what they are, and what it makes of
|
|
3
|
-
* what a killed process left behind.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import test from "node:test";
|
|
7
|
-
import assert from "node:assert/strict";
|
|
8
|
-
import { mkdtempSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
-
import os from "node:os";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { directoryNameFor, SegmentStore } from "../services/encode/SegmentStore.js";
|
|
12
|
-
import { fmp4Format } from "../services/segment-formats/fmp4.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @returns {{ store: SegmentStore, root: string, lines: string[] }}
|
|
16
|
-
*/
|
|
17
|
-
function storeInATempRoot() {
|
|
18
|
-
const root = mkdtempSync(path.join(os.tmpdir(), "segment-store-"));
|
|
19
|
-
const lines = [];
|
|
20
|
-
const store = new SegmentStore({
|
|
21
|
-
root,
|
|
22
|
-
logger: { info: (line) => lines.push(line), warn: (line) => lines.push(line) }
|
|
23
|
-
});
|
|
24
|
-
return { store, root, lines };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {string} dir
|
|
29
|
-
* @param {number} index
|
|
30
|
-
* @param {number} bytes
|
|
31
|
-
*/
|
|
32
|
-
function writeSegment(dir, index, bytes = 16) {
|
|
33
|
-
writeFileSync(path.join(dir, fmp4Format.segmentFileName(index)), Buffer.alloc(bytes));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const KEY = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
37
|
-
|
|
38
|
-
test("two viewers of one output are given the same directory", (t) => {
|
|
39
|
-
const { store, root } = storeInATempRoot();
|
|
40
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
41
|
-
|
|
42
|
-
// Which viewer asked never enters it — the address is what the segments are.
|
|
43
|
-
assert.equal(store.directoryFor(KEY), store.directoryFor(KEY));
|
|
44
|
-
assert.notEqual(store.directoryFor(KEY), store.directoryFor(`${KEY}:other`));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test("the directory says what it holds, so a later process can tell", (t) => {
|
|
48
|
-
const { store, root } = storeInATempRoot();
|
|
49
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
50
|
-
|
|
51
|
-
const dir = store.directoryFor(KEY);
|
|
52
|
-
const names = readdirSync(dir);
|
|
53
|
-
assert.deepEqual(names, ["key.txt"]);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test("a
|
|
57
|
-
const { store, root } = storeInATempRoot();
|
|
58
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
59
|
-
|
|
60
|
-
const dir = store.directoryFor(KEY);
|
|
61
|
-
store.useFormat(KEY, fmp4Format);
|
|
62
|
-
writeSegment(dir, 0);
|
|
63
|
-
writeSegment(dir, 1);
|
|
64
|
-
writeSegment(dir, 2);
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
assert.
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("a
|
|
74
|
-
const { store, root } = storeInATempRoot();
|
|
75
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
76
|
-
|
|
77
|
-
const dir = store.directoryFor(KEY);
|
|
78
|
-
store.useFormat(KEY, fmp4Format);
|
|
79
|
-
writeSegment(dir, 0);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
store.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
assert.equal(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
assert.
|
|
167
|
-
assert.
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* @file One store of segments, addressed by what they are, and what it makes of
|
|
3
|
+
* what a killed process left behind.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { mkdtempSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { directoryNameFor, SegmentStore } from "../services/encode/SegmentStore.js";
|
|
12
|
+
import { fmp4Format } from "../services/segment-formats/fmp4.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @returns {{ store: SegmentStore, root: string, lines: string[] }}
|
|
16
|
+
*/
|
|
17
|
+
function storeInATempRoot() {
|
|
18
|
+
const root = mkdtempSync(path.join(os.tmpdir(), "segment-store-"));
|
|
19
|
+
const lines = [];
|
|
20
|
+
const store = new SegmentStore({
|
|
21
|
+
root,
|
|
22
|
+
logger: { info: (line) => lines.push(line), warn: (line) => lines.push(line) }
|
|
23
|
+
});
|
|
24
|
+
return { store, root, lines };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} dir
|
|
29
|
+
* @param {number} index
|
|
30
|
+
* @param {number} bytes
|
|
31
|
+
*/
|
|
32
|
+
function writeSegment(dir, index, bytes = 16) {
|
|
33
|
+
writeFileSync(path.join(dir, fmp4Format.segmentFileName(index)), Buffer.alloc(bytes));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const KEY = "torrent:abc:fmt=fmp4:grid=kf@0:video-only:v=0/copy";
|
|
37
|
+
|
|
38
|
+
test("two viewers of one output are given the same directory", (t) => {
|
|
39
|
+
const { store, root } = storeInATempRoot();
|
|
40
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
41
|
+
|
|
42
|
+
// Which viewer asked never enters it — the address is what the segments are.
|
|
43
|
+
assert.equal(store.directoryFor(KEY), store.directoryFor(KEY));
|
|
44
|
+
assert.notEqual(store.directoryFor(KEY), store.directoryFor(`${KEY}:other`));
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("the directory says what it holds, so a later process can tell", (t) => {
|
|
48
|
+
const { store, root } = storeInATempRoot();
|
|
49
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
50
|
+
|
|
51
|
+
const dir = store.directoryFor(KEY);
|
|
52
|
+
const names = readdirSync(dir);
|
|
53
|
+
assert.deepEqual(names, ["key.txt"]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("a piece under its served name is finished, and the last one too", (t) => {
|
|
57
|
+
const { store, root } = storeInATempRoot();
|
|
58
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
59
|
+
|
|
60
|
+
const dir = store.directoryFor(KEY);
|
|
61
|
+
store.useFormat(KEY, fmp4Format);
|
|
62
|
+
writeSegment(dir, 0);
|
|
63
|
+
writeSegment(dir, 1);
|
|
64
|
+
writeSegment(dir, 2);
|
|
65
|
+
|
|
66
|
+
// It was "the NEXT number exists", which left the last piece of every run
|
|
67
|
+
// unprovable for ever and — the moment two runs share an output — declared a
|
|
68
|
+
// half-written file finished because somebody else had written the one after
|
|
69
|
+
// it. The name is the proof now, so all three count.
|
|
70
|
+
assert.deepEqual(store.provenNumbers(KEY), [0, 1, 2]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a piece still being written is not a piece, and its name says so", (t) => {
|
|
74
|
+
const { store, root } = storeInATempRoot();
|
|
75
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
76
|
+
|
|
77
|
+
const dir = store.directoryFor(KEY);
|
|
78
|
+
store.useFormat(KEY, fmp4Format);
|
|
79
|
+
writeSegment(dir, 0);
|
|
80
|
+
// What ffmpeg is writing into right now, tagged with the run that opened it.
|
|
81
|
+
writeFileSync(path.join(dir, "making-0-00001.mp4"), Buffer.alloc(64));
|
|
82
|
+
|
|
83
|
+
assert.deepEqual(store.provenNumbers(KEY), [0]);
|
|
84
|
+
assert.equal(store.isClosed(KEY, 1), false);
|
|
85
|
+
assert.equal(store.pathOf(KEY, 1), null);
|
|
86
|
+
|
|
87
|
+
// And closing it is one rename, after which it is servable.
|
|
88
|
+
assert.equal(store.publish(KEY, "making-0-00001.mp4", fmp4Format), "segment-00001.mp4");
|
|
89
|
+
assert.equal(store.isClosed(KEY, 1), true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("a file of no bytes is not a segment, whatever it is called", (t) => {
|
|
93
|
+
const { store, root } = storeInATempRoot();
|
|
94
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
95
|
+
|
|
96
|
+
const dir = store.directoryFor(KEY);
|
|
97
|
+
store.useFormat(KEY, fmp4Format);
|
|
98
|
+
writeSegment(dir, 0);
|
|
99
|
+
writeSegment(dir, 1);
|
|
100
|
+
writeSegment(dir, 2, 0);
|
|
101
|
+
|
|
102
|
+
// A file of no bytes under a served name cannot arise from this proxy any
|
|
103
|
+
// more — a piece takes that name only on being closed — but a killed process
|
|
104
|
+
// can leave one, and taking it for a segment once closed the only hole in the
|
|
105
|
+
// numbering and convinced the look-ahead the encoder had produced it.
|
|
106
|
+
assert.equal(store.pathOf(KEY, 2), null);
|
|
107
|
+
assert.deepEqual(store.provenNumbers(KEY), [0, 1]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("clearing up after one run leaves every other run's work alone", (t) => {
|
|
111
|
+
const { store, root } = storeInATempRoot();
|
|
112
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
113
|
+
|
|
114
|
+
const dir = store.directoryFor(KEY);
|
|
115
|
+
store.useFormat(KEY, fmp4Format);
|
|
116
|
+
// Two live runs, each with a piece open, plus finished pieces of both.
|
|
117
|
+
writeSegment(dir, 0);
|
|
118
|
+
writeSegment(dir, 100);
|
|
119
|
+
writeFileSync(path.join(dir, "making-0-00001.mp4"), Buffer.alloc(64));
|
|
120
|
+
writeFileSync(path.join(dir, "making-100-00101.mp4"), Buffer.alloc(64));
|
|
121
|
+
|
|
122
|
+
// The run that began at #0 ends. Its own unfinished piece goes and nothing
|
|
123
|
+
// else does — which the old rule could not manage: it took the highest SERVED
|
|
124
|
+
// name inside the ended run's stretch and judged its bytes, so with the
|
|
125
|
+
// naming rule above it would have removed #0, a piece that run had closed.
|
|
126
|
+
assert.equal(store.clearUpAfter(KEY, 0), 1);
|
|
127
|
+
assert.deepEqual(store.provenNumbers(KEY), [0, 100]);
|
|
128
|
+
assert.equal(
|
|
129
|
+
readdirSync(dir).includes("making-100-00101.mp4"),
|
|
130
|
+
true,
|
|
131
|
+
"the other run is still writing its own"
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a directory that has not moved is not read again", (t) => {
|
|
136
|
+
const { store, root } = storeInATempRoot();
|
|
137
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
138
|
+
|
|
139
|
+
const dir = store.directoryFor(KEY);
|
|
140
|
+
store.useFormat(KEY, fmp4Format);
|
|
141
|
+
writeSegment(dir, 0);
|
|
142
|
+
writeSegment(dir, 1);
|
|
143
|
+
|
|
144
|
+
const first = store.refresh(KEY);
|
|
145
|
+
const second = store.refresh(KEY);
|
|
146
|
+
assert.equal(first, second, "the same reading is handed back, not a fresh listing");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("what a killed process left is found, named and counted", (t) => {
|
|
150
|
+
const { store, root, lines } = storeInATempRoot();
|
|
151
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
152
|
+
|
|
153
|
+
const dir = path.join(root, directoryNameFor(KEY));
|
|
154
|
+
mkdirSync(dir, { recursive: true });
|
|
155
|
+
writeFileSync(path.join(dir, "key.txt"), `${KEY}\n`);
|
|
156
|
+
writeSegment(dir, 0);
|
|
157
|
+
writeSegment(dir, 1);
|
|
158
|
+
const orphan = path.join(root, "0123456789abcdef");
|
|
159
|
+
mkdirSync(orphan, { recursive: true });
|
|
160
|
+
writeSegment(orphan, 0);
|
|
161
|
+
|
|
162
|
+
const swept = store.sweep();
|
|
163
|
+
assert.equal(swept.directories, 2);
|
|
164
|
+
assert.equal(swept.unidentified, 1, "the one with no key file cannot be matched to a request");
|
|
165
|
+
assert.equal(swept.segments, 3);
|
|
166
|
+
assert.match(lines.join("\n"), /startup sweep/);
|
|
167
|
+
assert.match(lines.join("\n"), /ended\s+without anything recording why/);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("what survived a kill is taken back whole, minus what was still being written", (t) => {
|
|
171
|
+
const { store, root } = storeInATempRoot();
|
|
172
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
173
|
+
|
|
174
|
+
const dir = path.join(root, directoryNameFor(KEY));
|
|
175
|
+
mkdirSync(dir, { recursive: true });
|
|
176
|
+
writeFileSync(path.join(dir, "key.txt"), `${KEY}
|
|
177
|
+
`);
|
|
178
|
+
for (let index = 0; index <= 5; index += 1) {
|
|
179
|
+
writeSegment(dir, index);
|
|
180
|
+
}
|
|
181
|
+
// The piece the kernel interrupted. It never had a served name, so it cannot
|
|
182
|
+
// be mistaken for one — which is what the old rule could only guess at, by
|
|
183
|
+
// always throwing the highest number away.
|
|
184
|
+
writeFileSync(path.join(dir, "making-0-00006.mp4"), Buffer.alloc(64));
|
|
185
|
+
|
|
186
|
+
const taken = store.adoptWhatSurvived(() => fmp4Format);
|
|
187
|
+
|
|
188
|
+
assert.equal(taken.adopted, 1);
|
|
189
|
+
assert.equal(taken.unprovenRemoved, 1, "the one under a working name");
|
|
190
|
+
// All six kept rather than five: the highest served name used to be thrown
|
|
191
|
+
// away because nothing could prove it, and on the copy branch that is a piece
|
|
192
|
+
// whose bytes depend only on the source and cost a short machine to remake.
|
|
193
|
+
assert.deepEqual(store.provenNumbers(KEY), [0, 1, 2, 3, 4, 5]);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test("a directory that cannot name itself is thrown away rather than served", (t) => {
|
|
197
|
+
const { store, root } = storeInATempRoot();
|
|
198
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
199
|
+
|
|
200
|
+
const orphan = path.join(root, "0123456789abcdef");
|
|
201
|
+
mkdirSync(orphan, { recursive: true });
|
|
202
|
+
writeSegment(orphan, 0);
|
|
203
|
+
|
|
204
|
+
const taken = store.adoptWhatSurvived(() => fmp4Format);
|
|
205
|
+
|
|
206
|
+
assert.equal(taken.adopted, 0);
|
|
207
|
+
assert.equal(taken.dropped, 1);
|
|
208
|
+
assert.equal(readdirSync(root).length, 0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test("an output this proxy can no longer serve is thrown away too", (t) => {
|
|
212
|
+
const { store, root } = storeInATempRoot();
|
|
213
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
214
|
+
|
|
215
|
+
const dir = path.join(root, directoryNameFor(KEY));
|
|
216
|
+
mkdirSync(dir, { recursive: true });
|
|
217
|
+
writeFileSync(path.join(dir, "key.txt"), `${KEY}\n`);
|
|
218
|
+
writeSegment(dir, 0);
|
|
219
|
+
|
|
220
|
+
const taken = store.adoptWhatSurvived(() => null);
|
|
221
|
+
|
|
222
|
+
assert.equal(taken.dropped, 1);
|
|
223
|
+
assert.equal(readdirSync(root).length, 0);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("what the store weighs is reported, and dropping one output frees it", (t) => {
|
|
227
|
+
const { store, root } = storeInATempRoot();
|
|
228
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
229
|
+
|
|
230
|
+
const dir = store.directoryFor(KEY);
|
|
231
|
+
store.useFormat(KEY, fmp4Format);
|
|
232
|
+
writeSegment(dir, 0, 1000);
|
|
233
|
+
writeSegment(dir, 1, 1000);
|
|
234
|
+
|
|
235
|
+
assert.equal(store.stats().bytes, 2000);
|
|
236
|
+
store.drop(KEY, "nobody is watching it");
|
|
237
|
+
assert.equal(store.stats().outputs, 0);
|
|
238
|
+
});
|
|
@@ -140,7 +140,7 @@ test("what nobody has read for long enough goes, and time is the only judge", (t
|
|
|
140
140
|
clock += 60_000;
|
|
141
141
|
assert.deepEqual(
|
|
142
142
|
store.enforce({ idleMs: 3_600_000, maxBytes: 1e9 }),
|
|
143
|
-
{ droppedIdle: 0, droppedForRoom: 0, bytes: 32 }
|
|
143
|
+
{ droppedIdle: 0, droppedForRoom: 0, segmentsRemoved: 0, bytes: 32 }
|
|
144
144
|
);
|
|
145
145
|
|
|
146
146
|
clock += 7_200_000;
|
|
@@ -59,7 +59,7 @@ test("a stored piece comes back byte for byte", async () => {
|
|
|
59
59
|
assert.deepEqual(read, piece(0));
|
|
60
60
|
} finally {
|
|
61
61
|
await new Promise((resolve) => store.destroy(resolve));
|
|
62
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
62
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
|
|
@@ -79,7 +79,7 @@ test("pieces past the memory budget spill to disk and read back intact", async (
|
|
|
79
79
|
}
|
|
80
80
|
} finally {
|
|
81
81
|
await new Promise((resolve) => store.destroy(resolve));
|
|
82
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
82
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
|
|
@@ -99,7 +99,7 @@ test("the short last piece keeps its own length", async () => {
|
|
|
99
99
|
assert.deepEqual(read, tail);
|
|
100
100
|
} finally {
|
|
101
101
|
await new Promise((resolve) => store.destroy(resolve));
|
|
102
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
102
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
|
|
@@ -118,7 +118,7 @@ test("a buffer handed out survives later writes to the same slot", async () => {
|
|
|
118
118
|
assert.deepEqual(held, piece(0), "the buffer changed under its holder");
|
|
119
119
|
} finally {
|
|
120
120
|
await new Promise((resolve) => store.destroy(resolve));
|
|
121
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
121
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
|
@@ -139,7 +139,7 @@ test("a pinned piece is not evicted to make room", async () => {
|
|
|
139
139
|
store.unpin(0);
|
|
140
140
|
} finally {
|
|
141
141
|
await new Promise((resolve) => store.destroy(resolve));
|
|
142
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
142
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
|
|
@@ -160,7 +160,7 @@ test("refuses to make room when every resident piece is being read", async () =>
|
|
|
160
160
|
store.unpin(0);
|
|
161
161
|
store.unpin(1);
|
|
162
162
|
await new Promise((resolve) => store.destroy(resolve));
|
|
163
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
163
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
164
164
|
}
|
|
165
165
|
});
|
|
166
166
|
|
|
@@ -179,7 +179,7 @@ test("a piece revived from disk is readable by offset again", async () => {
|
|
|
179
179
|
assert.deepEqual(view, piece(0));
|
|
180
180
|
} finally {
|
|
181
181
|
await new Promise((resolve) => store.destroy(resolve));
|
|
182
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
182
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -205,7 +205,7 @@ test("a range within a piece is served correctly from memory and from disk", asy
|
|
|
205
205
|
);
|
|
206
206
|
} finally {
|
|
207
207
|
await new Promise((resolve) => store.destroy(resolve));
|
|
208
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
208
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
209
209
|
}
|
|
210
210
|
});
|
|
211
211
|
|
|
@@ -230,7 +230,7 @@ test("takes memory as it needs it, not the whole budget up front", async () => {
|
|
|
230
230
|
assert.deepEqual(await get(store, 0), piece(0), "an early piece was disturbed");
|
|
231
231
|
} finally {
|
|
232
232
|
await new Promise((resolve) => store.destroy(resolve));
|
|
233
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
233
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
|
|
@@ -257,7 +257,7 @@ test("counts where reads were served from, so the budget can be judged", async (
|
|
|
257
257
|
assert.equal(stats.capacity, 2);
|
|
258
258
|
} finally {
|
|
259
259
|
await new Promise((resolve) => store.destroy(resolve));
|
|
260
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
260
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
261
261
|
}
|
|
262
262
|
});
|
|
263
263
|
|
|
@@ -275,7 +275,7 @@ test("counts a refusal caused by pinned pieces", async () => {
|
|
|
275
275
|
store.unpin(0);
|
|
276
276
|
store.unpin(1);
|
|
277
277
|
await new Promise((resolve) => store.destroy(resolve));
|
|
278
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
278
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
|
|
@@ -292,5 +292,5 @@ test("destroy removes the spill file", async () => {
|
|
|
292
292
|
const after = await fs.readdir(directory);
|
|
293
293
|
assert.equal(after.length, 0, "the spill file outlived the store");
|
|
294
294
|
|
|
295
|
-
await fs.rm(directory, { recursive: true, force: true });
|
|
295
|
+
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10, retryDelay: 20 });
|
|
296
296
|
});
|