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

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Mar 7, 2019
1 parent da2e000 commit 0d8e8e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
17 changes: 6 additions & 11 deletions test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ describe('KadDHT', () => {
const dhtB = dhts[1]
const dhtC = dhts[2]
const dhtD = dhts[3]
const stub = sinon.stub(dhtD, '_verifyRecordLocally').callsArgWithAsync(1, error)
const stub = sinon.stub(dhtD, '_verifyRecordLocally').throws(error)

await connect(dhtA, dhtB)
await connect(dhtA, dhtC)
Expand All @@ -309,7 +309,7 @@ describe('KadDHT', () => {
})
})

it('put - should fail if not enough peers can be written to', function (done) {
it('put - should fail if not enough peers can be written to', function () {
this.timeout(10 * 1000)

const errCode = 'ERR_NOT_AVAILABLE'
Expand All @@ -320,8 +320,8 @@ describe('KadDHT', () => {
const dhtB = dhts[1]
const dhtC = dhts[2]
const dhtD = dhts[3]
const stub = sinon.stub(dhtD, '_verifyRecordLocally').callsArgWithAsync(1, error)
const stub2 = sinon.stub(dhtC, '_verifyRecordLocally').callsArgWithAsync(1, error)
const stub = sinon.stub(dhtD, '_verifyRecordLocally').throws(error)
const stub2 = sinon.stub(dhtC, '_verifyRecordLocally').throws(error)

await connect(dhtA, dhtB)
await connect(dhtA, dhtC)
Expand All @@ -338,24 +338,19 @@ describe('KadDHT', () => {
})
})

it('put - should require all peers to be put to successfully if no minPeers specified', function (done) {
it('put - should require all peers to be put to successfully if no minPeers specified', function () {
this.timeout(10 * 1000)

const errCode = 'ERR_NOT_AVAILABLE'
const error = errcode(new Error('fake error'), errCode)

return withDHTs(3, async ([dhtA, dhtB, dhtC]) => {
const stub = sinon.stub(dhtC, '_verifyRecordLocally').callsArgWithAsync(1, error)
const stub = sinon.stub(dhtC, '_verifyRecordLocally').throws(error)

await connect(dhtA, dhtB)
await connect(dhtA, dhtC)
try {
await dhtA.put(Buffer.from('/v/hello'), Buffer.from('world'), { minPeers: 2 })
// (cb) => dhtB.get(Buffer.from('/v/hello'), { timeout: 1000 }, cb),
// (res, cb) => {
// expect(res).to.eql(Buffer.from('world'))
// cb()
// }
} catch (err) {
expect(err.code).to.eql('ERR_NOT_ENOUGH_PUT_PEERS')
stub.restore()
Expand Down
3 changes: 0 additions & 3 deletions test/rpc/handlers/add-provider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ describe('rpc - handlers - AddProvider', () => {
const tests = [{
message: new Message(Message.TYPES.ADD_PROVIDER, Buffer.alloc(0), 0),
error: 'ERR_MISSING_KEY'
}, {
message: new Message(Message.TYPES.ADD_PROVIDER, Buffer.alloc(0), 0),
error: 'ERR_MISSING_KEY'
}, {
message: new Message(Message.TYPES.ADD_PROVIDER, Buffer.from('hello world'), 0),
error: 'ERR_INVALID_CID'
Expand Down

0 comments on commit 0d8e8e0

Please sign in to comment.