Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PeerList][Part 5] SinglePeerList #403

Merged
merged 7 commits into from
Nov 10, 2016
Merged

Conversation

willhug
Copy link
Contributor

@willhug willhug commented Nov 2, 2016

Summary: This PR creates a concrete peerlist implementation that has a
single peer implementation.

@willhug willhug force-pushed the peerList-part4-refactor branch 3 times, most recently from 67423a5 to 9dd824b Compare November 8, 2016 02:14
@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from 6d416e7 to 2b4961f Compare November 8, 2016 03:34

type single struct {
peerID transport.PeerIdentifier
peer transport.Peer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to assume that peerID is irrelevant once peer is set? Maybe mention that in a comment?

}

// NotifyPending when the number of Pending requests changes
func (pl *single) NotifyStatusChanged(transport.Peer) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping


func (pl *single) Start() error {
if pl.started.Swap(true) {
return errors.ErrPeerListAlreadyStarted("single")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use a RW Mutex instead. There's a race here where if I
call Start and ChoosePeer concurrently, started is set to true by
Start but ChoosePeer returns the nil peer before Start has a chance to
fill it in.

}

// NotifyPending when the number of Pending requests changes
func (pl *single) NotifyStatusChanged(transport.Peer) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping

s.expectedPeerID = s.pid
s.expectedAgent = s.agent
s.expectedStarted = false
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of combining all these tests, it's okay (preferable even) to split
tests for different behaviors out into different test functions. Table tests
are for tests with enough similar structure that writing those into separate
functions would be redundant. As it stands right now, it's very difficult to
figure out what each of these tests is actually testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

// NewSingle creates a static PeerList with a single Peer
func NewSingle(pi transport.PeerIdentifier, agent transport.Agent) transport.PeerList {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency! pid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

85351-dale-shhh-gif-the-walking-dead-pzrw

}

for _, tt := range tests {
pl := NewSingle(tt.pid, tt.agent).(*single)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtests :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil
}

func (pl *single) ChoosePeer(context.Context, *transport.Request) (transport.Peer, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do I understand that every new request will call this function first locking the mutex on the way?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a read lock yes, for this list it doesn't make as much sense, but once we start adding/removing peers I think it will be a good idea, or at least we'll need to be explicitly aware when we remove the mutexes (for performance reasons).

@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from a8ab052 to 04165b8 Compare November 10, 2016 05:35
@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from 04165b8 to 99078d1 Compare November 10, 2016 05:44
@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from 99078d1 to 91af1f5 Compare November 10, 2016 06:29
@willhug willhug changed the base branch from peerList-part4-refactor to peerList November 10, 2016 07:18
@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from 91af1f5 to 955c76f Compare November 10, 2016 07:19
@willhug willhug force-pushed the peerList-part5-singlepeerlist branch from 955c76f to e3c5ff2 Compare November 10, 2016 07:20
@willhug willhug merged commit 5615ce2 into peerList Nov 10, 2016
@willhug willhug deleted the peerList-part5-singlepeerlist branch November 10, 2016 19:12
willhug added a commit that referenced this pull request Nov 10, 2016
Summary: This PR creates a concrete peerlist implementation that has a
single peer implementation.  This can be used to shim the current existing http outbounds and replace them with a single PeerList
willhug added a commit that referenced this pull request Nov 10, 2016
Summary: This PR creates a concrete peerlist implementation that has a
single peer implementation.  This can be used to shim the current existing http outbounds and replace them with a single PeerList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants