@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.
Files changed (67) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/docs/encode-architecture.md +51 -2
  3. package/package.json +1 -1
  4. package/research/double-spawn-2026-09-10.md +171 -0
  5. package/services/disk/DiskSpace.js +146 -0
  6. package/services/disk/wire.js +60 -0
  7. package/services/encode/EncodeRun.js +37 -9
  8. package/services/encode/SegmentStore.js +284 -232
  9. package/services/encode/run-command.js +16 -1
  10. package/services/hls-session-manager.js +31 -128
  11. package/services/orchestrators/EncodeOrchestrator.js +52 -38
  12. package/services/piece-store/allowance.js +107 -0
  13. package/services/piece-store/piece-disk-store.js +365 -0
  14. package/services/piece-store/shared-piece-store.js +1549 -1535
  15. package/services/segment-formats/fmp4.js +54 -0
  16. package/services/segment-formats/mpegts.js +54 -0
  17. package/services/torrent-worker/client.js +32 -0
  18. package/services/torrent-worker/pool-adapter.js +15 -0
  19. package/services/torrent-worker/protocol.js +9 -0
  20. package/services/torrent-worker/worker.js +8 -1
  21. package/services/viewer/positions.js +48 -0
  22. package/test/audio-inventory.test.js +176 -176
  23. package/test/auto-quality-step.test.js +514 -514
  24. package/test/concurrent-cost.test.js +138 -138
  25. package/test/coverage-follows-the-disk.test.js +191 -187
  26. package/test/coverage-map.test.js +195 -195
  27. package/test/declared-tracks.test.js +35 -35
  28. package/test/disk-space.test.js +138 -0
  29. package/test/encode-orchestrator.test.js +0 -3
  30. package/test/encode-run.test.js +5 -12
  31. package/test/held-request-width.test.js +155 -155
  32. package/test/helpers/encode-run.js +2 -2
  33. package/test/matroska-blocks.test.js +0 -0
  34. package/test/matroska-cues-track.test.js +192 -192
  35. package/test/mp4-composition-times.test.js +0 -0
  36. package/test/mp4-subtitles.test.js +173 -173
  37. package/test/one-authority.test.js +281 -220
  38. package/test/orchestrator-wired.test.js +199 -195
  39. package/test/packet-witness-ring.test.js +236 -236
  40. package/test/packet-witness.test.js +148 -148
  41. package/test/piece-disk-store.test.js +267 -0
  42. package/test/piece-reader.test.js +4 -4
  43. package/test/piece-store-eviction.test.js +17 -17
  44. package/test/piece-store-reservations.test.js +20 -1
  45. package/test/piece-store-slow-disk.test.js +16 -1
  46. package/test/produced-copy-choice.test.js +258 -358
  47. package/test/read-window.test.js +6 -6
  48. package/test/run-intervals.test.js +100 -100
  49. package/test/seek-landing.test.js +109 -109
  50. package/test/segment-serve-wiring.test.js +8 -9
  51. package/test/segment-store-eviction.test.js +232 -0
  52. package/test/segment-store.test.js +238 -216
  53. package/test/segments-are-shared.test.js +1 -1
  54. package/test/shared-piece-store.test.js +12 -12
  55. package/test/sidecar-naming.test.js +142 -142
  56. package/test/subtitle-cue-framing.test.js +200 -200
  57. package/test/subtitle-cue-walk.test.js +369 -369
  58. package/test/subtitle-defaults.test.js +97 -97
  59. package/test/subtitle-track-numbering.test.js +370 -370
  60. package/test/tail-duplication.test.js +167 -167
  61. package/test/tracks-begin-together.test.js +195 -195
  62. package/test/two-viewers-one-picture.test.js +374 -374
  63. package/test/video-facts.test.js +102 -102
  64. package/test/wedge-certainty.test.js +131 -131
  65. package/services/encode/open-piece.js +0 -135
  66. package/services/piece-store/disk-tier.js +0 -151
  67. 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 segment is proven closed by the existence of the next one", (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
- // The `hls` muxer carries no channel to report on and renames into place when
67
- // it closes a piece, so on that branch existence IS the proof; the same
68
- // answers for the pieces a previous life of this process left behind.
69
- assert.deepEqual(store.provenNumbers(KEY), [0, 1]);
70
- assert.equal(store.unprovenNumber(KEY), 2);
71
- });
72
-
73
- test("a file of no bytes is not a segment, whatever it is called", (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
- writeSegment(dir, 1);
81
- writeSegment(dir, 2, 0);
82
-
83
- // What a run killed the moment after opening its next piece leaves behind.
84
- // Counted as a segment once, it closed the only hole in the numbering and
85
- // convinced the look-ahead the encoder had produced it.
86
- assert.equal(store.pathOf(KEY, 2), null);
87
- assert.deepEqual(store.provenNumbers(KEY), [0]);
88
- });
89
-
90
- test("a run's own stretch bounds what it unproves", (t) => {
91
- const { store, root } = storeInATempRoot();
92
- t.after(() => rmSync(root, { recursive: true, force: true }));
93
-
94
- store.useFormat(KEY, fmp4Format);
95
- store.directoryFor(KEY);
96
- for (let index = 0; index <= 5; index += 1) {
97
- store.markClosed(KEY, index);
98
- }
99
-
100
- // A run of #0..#0 rewrites #0 and nothing else. Unbounded, this forgot the
101
- // whole film beyond it — and with readiness a projection of what is proven,
102
- // that is an output declaring itself unmade whenever an encoder starts near
103
- // the beginning, which is a fresh encoder for every segment of it.
104
- //
105
- // Asked with no files on the disk, so the successor rule cannot answer for
106
- // the statements and only the statements are under test.
107
- store.forgetClosed(KEY, 0, 0);
108
- assert.equal(store.isClosed(KEY, 0), false, "the one number it will rewrite");
109
- assert.equal(store.isClosed(KEY, 1), true, "and nothing beyond its stretch");
110
- assert.equal(store.isClosed(KEY, 5), true);
111
-
112
- store.forgetClosed(KEY, 3);
113
- assert.equal(store.isClosed(KEY, 2), true);
114
- assert.equal(store.isClosed(KEY, 3), false, "no end given means to the end of the film");
115
- assert.equal(store.isClosed(KEY, 5), false);
116
- });
117
-
118
- test("a directory that has not moved is not read again", (t) => {
119
- const { store, root } = storeInATempRoot();
120
- t.after(() => rmSync(root, { recursive: true, force: true }));
121
-
122
- const dir = store.directoryFor(KEY);
123
- store.useFormat(KEY, fmp4Format);
124
- writeSegment(dir, 0);
125
- writeSegment(dir, 1);
126
-
127
- const first = store.refresh(KEY);
128
- const second = store.refresh(KEY);
129
- assert.equal(first, second, "the same reading is handed back, not a fresh listing");
130
- });
131
-
132
- test("what a killed process left is found, named and counted", (t) => {
133
- const { store, root, lines } = storeInATempRoot();
134
- t.after(() => rmSync(root, { recursive: true, force: true }));
135
-
136
- const dir = path.join(root, directoryNameFor(KEY));
137
- mkdirSync(dir, { recursive: true });
138
- writeFileSync(path.join(dir, "key.txt"), `${KEY}\n`);
139
- writeSegment(dir, 0);
140
- writeSegment(dir, 1);
141
- const orphan = path.join(root, "0123456789abcdef");
142
- mkdirSync(orphan, { recursive: true });
143
- writeSegment(orphan, 0);
144
-
145
- const swept = store.sweep();
146
- assert.equal(swept.directories, 2);
147
- assert.equal(swept.unidentified, 1, "the one with no key file cannot be matched to a request");
148
- assert.equal(swept.segments, 3);
149
- assert.match(lines.join("\n"), /startup sweep/);
150
- assert.match(lines.join("\n"), /ended\s+without anything recording why/);
151
- });
152
-
153
- test("what survived a kill is taken back, minus the piece nothing proves", (t) => {
154
- const { store, root } = storeInATempRoot();
155
- t.after(() => rmSync(root, { recursive: true, force: true }));
156
-
157
- const dir = path.join(root, directoryNameFor(KEY));
158
- mkdirSync(dir, { recursive: true });
159
- writeFileSync(path.join(dir, "key.txt"), `${KEY}\n`);
160
- for (let index = 0; index <= 5; index += 1) {
161
- writeSegment(dir, index);
162
- }
163
-
164
- const taken = store.adoptWhatSurvived(() => fmp4Format);
165
-
166
- assert.equal(taken.adopted, 1);
167
- assert.equal(taken.unprovenRemoved, 1, "the highest number was being written when the run died");
168
- // Five kept rather than six thrown away: a copied segment's bytes depend only
169
- // on the source, and re-encoding them costs a machine already short of it.
170
- assert.deepEqual(store.provenNumbers(KEY), [0, 1, 2, 3, 4]);
171
- assert.equal(store.pathOf(KEY, 5), null);
172
- });
173
-
174
- test("a directory that cannot name itself is thrown away rather than served", (t) => {
175
- const { store, root } = storeInATempRoot();
176
- t.after(() => rmSync(root, { recursive: true, force: true }));
177
-
178
- const orphan = path.join(root, "0123456789abcdef");
179
- mkdirSync(orphan, { recursive: true });
180
- writeSegment(orphan, 0);
181
-
182
- const taken = store.adoptWhatSurvived(() => fmp4Format);
183
-
184
- assert.equal(taken.adopted, 0);
185
- assert.equal(taken.dropped, 1);
186
- assert.equal(readdirSync(root).length, 0);
187
- });
188
-
189
- test("an output this proxy can no longer serve is thrown away too", (t) => {
190
- const { store, root } = storeInATempRoot();
191
- t.after(() => rmSync(root, { recursive: true, force: true }));
192
-
193
- const dir = path.join(root, directoryNameFor(KEY));
194
- mkdirSync(dir, { recursive: true });
195
- writeFileSync(path.join(dir, "key.txt"), `${KEY}\n`);
196
- writeSegment(dir, 0);
197
-
198
- const taken = store.adoptWhatSurvived(() => null);
199
-
200
- assert.equal(taken.dropped, 1);
201
- assert.equal(readdirSync(root).length, 0);
202
- });
203
-
204
- test("what the store weighs is reported, and dropping one output frees it", (t) => {
205
- const { store, root } = storeInATempRoot();
206
- t.after(() => rmSync(root, { recursive: true, force: true }));
207
-
208
- const dir = store.directoryFor(KEY);
209
- store.useFormat(KEY, fmp4Format);
210
- writeSegment(dir, 0, 1000);
211
- writeSegment(dir, 1, 1000);
212
-
213
- assert.equal(store.stats().bytes, 2000);
214
- store.drop(KEY, "nobody is watching it");
215
- assert.equal(store.stats().outputs, 0);
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
  });