Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(resources): keep the dropped-download specs from flaking
Elian Doran77cc250e9bc4
diff --git a/apps/server/src/services/resources.spec.ts b/apps/server/src/services/resources.spec.tsindex a818c8591b..d7f66cbcbd 100644--- a/apps/server/src/services/resources.spec.ts+++ b/apps/server/src/services/resources.spec.ts@@ -499,7 +499,10 @@ function serveModel(req: http.IncomingMessage, res: http.ServerResponse) {const length = dropModelAfter;dropModelAfter = null;res.writeHead(200, { "Content-Length": MODEL.length });- res.write(MODEL.subarray(0, length), () => setTimeout(() => res.destroy(), 20));+ res.write(MODEL.subarray(0, length));+ // A reset that arrives before the client reads the bytes discards them.+ const drop = () => res.destroy();+ waitFor(() => partialModelSize() === length).then(drop, drop);} else {res.end(MODEL);}@@ -537,6 +540,13 @@ async function waitForEnd() {return last;}+/** The size of the `.partial` a download of `test.model` writes its model to, or 0 before it exists. */+function partialModelSize() {+ const directory = fs.readdirSync(baseDir).find((name) => name.startsWith("test.model-"));+ const partial = directory && path.join(baseDir, directory, "nested", "model.bin.partial");+ return partial && fs.existsSync(partial) ? fs.statSync(partial).size : 0;+}+async function waitFor(condition: () => boolean) {const deadline = Date.now() + 5000;while (!condition()) {