This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(bootstrap:add): prevent duplicate inserts #893
Merged
+25
−2
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,27 @@ module.exports = (ctl) => { | |
}) | ||
}) | ||
|
||
it('prevents duplicate inserts of bootstrap peers', () => { | ||
return ctl | ||
.bootstrap | ||
.add(validIp4) | ||
.then(res => { | ||
expect(res).to.be.eql({ Peers: [validIp4] }) | ||
return ctl.bootstrap.add(validIp4) | ||
}) | ||
.then((res) => { | ||
expect(res).to.be.eql({ Peers: [validIp4] }) | ||
return ctl.bootstrap.list() | ||
}) | ||
.then((res) => { | ||
expect(res).to.exist() | ||
const insertPosition = res.Peers.indexOf(validIp4) | ||
expect(insertPosition).to.not.equal(-1) | ||
const duplicatePosition = res.Peers.indexOf(validIp4, insertPosition + 1) | ||
expect(duplicatePosition).to.equal(-1) | ||
}) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please write tests for |
||
|
||
it('returns a list of bootstrap peers when called with the default option', (done) => { | ||
ctl.bootstrap.add({ default: true }, (err, res) => { | ||
expect(err).to.not.exist() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a expectation about that the bootstrap list should now only have one element in it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 46 verifies if the newly added peer was inserted. The bootstrap list contains the default peer list from https://github.com/ipfs/js-ipfs/tree/master/src/init-files + the ones added manually so it won't have only one element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, you're asserting that validIp4 is not missing from the list of peers, but never asserting that the amount of peers are correct in the test-case. Ideal, minimal test-case would start with a empty bootstrap list, add the same address twice and assert that the list only contain once element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That way, this test would also be protected against future changes (additions/removal of peers) to the default bootstrap list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, how do I set the bootstrap list to be empty without calling rm for the default bootstrap list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not getting your question @victorbjelkholm, these test nodes have their bootstrap lists empty by default:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that was what I thought... @kenshyx then you can remove the
.rm
call and just add the two addresses.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kenshyx is doing
rm
because the previous tests add up to the bootstrap peers pool