chaintnfs/btcdnotify: make cancellation of block epoch synchronous

This commit is meant to fix an occasional flake in the interrogation
tests cause by the async nature of the cancellation of block epoch
notifications. This commit modifies the cancellation to now be fully
synchronous which should eliminate this flake.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-26 21:08:16 -07:00
parent f9c78b7c2b
commit c575107607
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -262,6 +262,8 @@ out:
close(b.blockEpochClients[msg.epochID])
delete(b.blockEpochClients, msg.epochID)
close(msg.done)
}
case registerMsg := <-b.notificationRegistry:
switch msg := registerMsg.(type) {
@ -707,6 +709,8 @@ type blockEpochRegistration struct {
// cancel an outstanding epoch notification that has yet to be dispatched.
type epochCancel struct {
epochID uint64
done chan struct{}
}
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the
@ -726,10 +730,17 @@ func (b *BtcdNotifier) RegisterBlockEpochNtfn() (*chainntnfs.BlockEpochEvent, er
return &chainntnfs.BlockEpochEvent{
Epochs: registration.epochChan,
Cancel: func() {
select {
case b.notificationCancels <- &epochCancel{
cancel := &epochCancel{
epochID: registration.epochID,
}:
done: make(chan struct{}),
}
select {
case b.notificationCancels <- cancel:
select {
case <-cancel.done:
case <-b.quit:
}
case <-b.quit:
return
}