diff --git a/src/adapters/ipfs/index.js b/src/adapters/ipfs/index.js index 320fb87..df12983 100644 --- a/src/adapters/ipfs/index.js +++ b/src/adapters/ipfs/index.js @@ -10,6 +10,7 @@ class IPFS { // Encapsulate dependencies this.ipfsAdapter = new IpfsAdapter() this.IpfsCoordAdapter = IpfsCoordAdapter + this.process = process this.ipfsCoordAdapter = {} // placeholder @@ -42,7 +43,7 @@ class IPFS { // If error is due to a lock file issue. Kill the process, so that // Docker or pm2 has a chance to restart the service. if (err.message.includes('Lock already being held')) { - process.exit(1) + this.process.exit(1) } throw err diff --git a/test/unit/adapters/ipfs-index.adapter.unit.js b/test/unit/adapters/ipfs-index.adapter.unit.js index 1d46622..3c36911 100644 --- a/test/unit/adapters/ipfs-index.adapter.unit.js +++ b/test/unit/adapters/ipfs-index.adapter.unit.js @@ -45,5 +45,23 @@ describe('#IPFS-adapter-index', () => { assert.include(err.message, 'test error') } }) + + it('should handle lock-file errors', async () => { + try { + // Force an error + sandbox + .stub(uut.ipfsAdapter, 'start') + .rejects(new Error('Lock already being held')) + + // Prevent process from exiting + sandbox.stub(uut.process, 'exit').returns() + + await uut.start() + + assert.fail('Unexpected code path.') + } catch (err) { + assert.include(err.message, 'Lock already being held') + } + }) }) })