Skip to content

Commit

Permalink
fix: remove onBlocked hook from delete database (#509)
Browse files Browse the repository at this point in the history
the onblocked hook should be optional and not reject the promise from delete database
  • Loading branch information
achingbrain committed May 13, 2020
1 parent 528d497 commit e4d6f80
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"temp-write": "^4.0.0"
},
"devDependencies": {
"aegir": "^21.10.2",
"aegir": "^22.0.0",
"benchmark": "^2.1.4",
"go-ipfs-dep": "^0.5.0",
"husky": "^4.2.5",
Expand Down
1 change: 0 additions & 1 deletion src/utils.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { nanoid } = require('nanoid')
const deleteDb = (path) => {
return new Promise((resolve, reject) => {
const keys = self.indexedDB.deleteDatabase(path)
keys.onblocked = () => reject(new Error('Database is still open.'))
keys.onerror = (err) => reject(err)
keys.onsuccess = () => resolve()
})
Expand Down
22 changes: 22 additions & 0 deletions test/browser.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,28 @@ describe('utils browser version', function () {
expect(await repoExists('ipfs_test_remove/datastore')).to.be.false()
})

it('removeRepo should wait for db to be closed', async () => {
const ctl = await createController({
test: true,
type: 'proc',
disposable: false,
ipfsOptions: { repo: 'ipfs_test_remove' },
ipfsModule: require('ipfs')
})
await ctl.init()
await ctl.start()

await Promise.all([
removeRepo('ipfs_test_remove'),
ctl.stop()
])

expect(await repoExists('ipfs_test_remove')).to.be.false()
expect(await repoExists('ipfs_test_remove/keys')).to.be.false()
expect(await repoExists('ipfs_test_remove/blocks')).to.be.false()
expect(await repoExists('ipfs_test_remove/datastore')).to.be.false()
})

describe('repoExists', () => {
it('should resolve true when repo exists', async () => {
const f = createFactory({ test: true })
Expand Down

0 comments on commit e4d6f80

Please sign in to comment.