Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: fix async sharding tests (#49)
Browse files Browse the repository at this point in the history
`open - empty` was failing with an uncaught exception but this wasn't failing mocha or karma.

Found this problem testing playwright-test in this repo.
  • Loading branch information
hugomrdias authored Feb 2, 2021
1 parent 0ff7465 commit a546afb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/sharding.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { Adapter, Key, utils: { utf8Encoder } } = require('interface-datastore')
const { Adapter, Key, utils: { utf8Encoder }, Errors } = require('interface-datastore')
const sh = require('./shard')
const KeytransformStore = require('./keytransform')

Expand Down Expand Up @@ -100,6 +100,9 @@ class ShardingDatastore extends Adapter {
*/
static async create (store, shard) {
const hasShard = await store.has(shardKey)
if (!hasShard && !shard) {
throw Errors.dbOpenFailedError(Error('Shard is required when datastore doesn\'t have a shard key already.'))
}
if (!hasShard) {
// @ts-ignore i have no idea what putRaw is or saw any implementation
const put = typeof store.putRaw === 'function' ? store.putRaw.bind(store) : store.put.bind(store)
Expand Down
10 changes: 5 additions & 5 deletions test/sharding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ describe('ShardingStore', () => {
expect(utf8Decoder.decode(res[1])).to.eql(sh.readme)
})

it('open - empty', async () => {
it('open - empty', () => {
const ms = new MemoryDatastore()
// @ts-expect-error
const store = new ShardingStore(ms)
expect(store.open())
return expect(store.open())
.to.eventually.be.rejected()
.with.property('code', 'ERR_NOT_FOUND')
.with.property('code', 'ERR_DB_OPEN_FAILED')
})

it('open - existing', async () => {
it('open - existing', () => {
const ms = new MemoryDatastore()
const shard = new sh.NextToLast(2)
const store = new ShardingStore(ms, shard)

expect(store.open()).to.eventually.be.fulfilled()
return expect(store.open()).to.eventually.be.fulfilled()
})

it('basics', async () => {
Expand Down

0 comments on commit a546afb

Please sign in to comment.