Skip to content

Commit

Permalink
Kill crashed bot in test by running in separate process
Browse files Browse the repository at this point in the history
  • Loading branch information
Powersource committed Nov 7, 2023
1 parent ab28827 commit bf6a4f9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 15 additions & 4 deletions test/from-old-versions.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const test = require('tape')
const { promisify: p } = require('util')
const childProcess = require('node:child_process')

const OldTestBot = require('scuttle-testbot-1-11-0')
const NewBot = require('./helpers/test-bot')
const { join } = require('path')

const OldBot = (opts) => {
let stack = OldTestBot // eslint-disable-line
Expand Down Expand Up @@ -34,15 +36,24 @@ test('can continue from old keyring from ssb-tribes 3.1.3', async t => {

await p(setTimeout)(500)

// we have to do it this way because we have no normal way of killing a bot that's crashed and therefore releasing its DB locks.
const throwChild = childProcess.fork(join(__dirname, 'helpers/throw-bot.js'))

await new Promise((res) => {
throwChild.on("message", (msg) => {
t.match(msg, /found an old keystore/, "error when there's an old keystore but we don't use it")

throwChild.kill()

res()
})
})

const newOpts = {
name: 'alice',
startUnclean: true
}

// t.throws(() => {
// NewBot(newOpts)
// }, /found an old keystore/, "Error when there's an old keystore but we don't use it")

const newAlice = NewBot({
...newOpts,
box2: {
Expand Down
14 changes: 14 additions & 0 deletions test/helpers/throw-bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// this file is used in test/from-old-versions.test.js

const NewBot = require('./test-bot')

const newOpts = {
name: 'alice',
startUnclean: true
}

try {
NewBot(newOpts)
} catch (err) {
process.send(err.message)
}

0 comments on commit bf6a4f9

Please sign in to comment.