Browse Source

statesync: dispatcher test uses internal channel for timing (#6713)

This code change amends the dispatcher tests to read from the dispatcher's `requestCh`. This ensures that a request is waiting when the test calls `dispatcher.respond`. 
addresses: #6711
pull/6723/head
William Banfield 4 years ago
committed by GitHub
parent
commit
a46724e4f6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions
  1. +10
    -4
      internal/statesync/dispatcher_test.go

+ 10
- 4
internal/statesync/dispatcher_test.go View File

@ -60,8 +60,8 @@ func TestDispatcherReturnsNoBlock(t *testing.T) {
doneCh := make(chan struct{})
go func() {
err := d.respond(nil, peerFromSet)
require.Nil(t, err)
<-ch
require.NoError(t, d.respond(nil, peerFromSet))
close(doneCh)
}()
@ -87,8 +87,8 @@ func TestDispatcherErrorsWhenNoPeers(t *testing.T) {
func TestDispatcherReturnsBlockOncePeerAvailable(t *testing.T) {
t.Cleanup(leaktest.Check(t))
ch := make(chan p2p.Envelope, 100)
d := newDispatcher(ch, 1*time.Second)
dispatcherRequestCh := make(chan p2p.Envelope, 100)
d := newDispatcher(dispatcherRequestCh, 1*time.Second)
peerFromSet := createPeerSet(1)[0]
d.addPeer(peerFromSet)
ctx := context.Background()
@ -100,12 +100,18 @@ func TestDispatcherReturnsBlockOncePeerAvailable(t *testing.T) {
require.Nil(t, lb)
require.Equal(t, peerFromSet, peerResult)
require.Nil(t, err)
// calls to dispatcher.Lightblock write into the dispatcher's requestCh.
// we read from the requestCh here to unblock the requestCh for future
// calls.
<-dispatcherRequestCh
close(doneCh)
}()
cancelFunc()
<-doneCh
go func() {
<-dispatcherRequestCh
lb := &types.LightBlock{}
asProto, err := lb.ToProto()
require.Nil(t, err)


Loading…
Cancel
Save