Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class IpfsRepo {
}
}

await Promise.all([this.blocks, this.keys, this.datastore].map((store) => store.close()))
await Promise.all([this.root, this.blocks, this.keys, this.datastore].map((store) => store.close()))
log('unlocking')
this.closed = true
await this._closeLock()
Expand Down
54 changes: 54 additions & 0 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,60 @@ module.exports = (repo) => {
expect.fail('Did not throw')
})

it('should close all the datastores', async () => {
let count = 0
class FakeDatastore {
constructor () {
this.data = {}
}

async open () {}

// eslint-disable-next-line require-await
async put (key, val) {
this.data[key.toString()] = val
}

async get (key) {
const exists = await this.has(key)
if (!exists) throw Errors.notFoundError()
return this.data[key.toString()]
}

// eslint-disable-next-line require-await
async has (key) {
return this.data[key.toString()] !== undefined
}

// eslint-disable-next-line require-await
async delete (key) {
delete this.data[key.toString()]
}

batch () {}

query (q) {}

// eslint-disable-next-line require-await
async close () {
count++
}
}
const repo = new IPFSRepo(path.join(os.tmpdir(), 'repo-' + Date.now()), {
lock: 'memory',
storageBackends: {
root: FakeDatastore,
blocks: FakeDatastore,
keys: FakeDatastore,
datastore: FakeDatastore
}
})
await repo.init({})
await repo.open()
await repo.close()
expect(count).to.be.eq(4)
})

it('open twice throws error', async () => {
await repo.open()
try {
Expand Down