Skip to content

Commit

Permalink
Fix tests and remove workaround
Browse files Browse the repository at this point in the history
Problem: Recently there was a PR [0] merged with a quickfix to avoid
some test failures, which is something I've been trying to avoid. While
`process.exit()` works fine, I'm worried that it means we don't
understand what's happening under the hood, *plus* I have the [maybe
unjustified?] worry that it might kill the process during a database
write or something dangerous. It looks like this particular test hang
was caused by both a stream and some number of intervals that were left
open.

Solution: Provide a way to close the stream and intervals in `index.js`
and ensure that we do that before closing the server.

[0]: fraction#462
  • Loading branch information
christianbundy committed Nov 11, 2020
1 parent 4e0960d commit 0aacf3b
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 82 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"OSSEC",
"Pieter",
"Termux",
"abortable",
"autoconf",
"automake",
"backlinks",
Expand Down
70 changes: 47 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"open": "^7.0.3",
"piexifjs": "^1.0.4",
"pretty-ms": "^6.0.0",
"pull-abortable": "^4.1.1",
"pull-paramap": "^1.2.2",
"pull-sort": "^1.0.2",
"pull-stream": "^3.6.12",
Expand Down
12 changes: 3 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ const { about, blob, friend, meta, post, vote } = require("./models")({
isPublic: config.public,
});

const nameWarmup = about._startNameWarmup();

// enhance the users' input text by expanding @name to [@name](@feedPub.key)
// and slurps up blob uploads and appends a markdown link for it to the text (see handleBlobUpload)
const preparePreview = async function (ctx) {
Expand Down Expand Up @@ -1058,16 +1060,8 @@ const app = http({ host, port, middleware, allowHost });
// If we close the database after each test it throws lots of really fun "parent
// stream closing" errors everywhere and breaks the tests. :/
app._close = () => {
nameWarmup.close();
cooler.close();
// HACK: app._close is called when everything is supposed to have finished;
// cooler.close successfully stops the ssb-db process. we create a timeout
// to definitively kill the server and thereby circumvent the node process
// staying alive despite all signals pointing to the app exiting. more
// context when it was originally
// introduced in this PR: https://github.com/fraction/oasis/pull/462
setTimeout(() => {
process.exit();
}, 20000);
};

module.exports = app;
Expand Down
Loading

0 comments on commit 0aacf3b

Please sign in to comment.