chainntnfs/test: add new test assertion to ensure block epoch headers set

This commit is contained in:
Olaoluwa Osuntokun 2021-08-11 16:05:36 -07:00
parent 67aa7a0df7
commit 0d8ffd95dd
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -393,7 +393,6 @@ func testBlockEpochNotification(miner *rpctest.Harness,
// We'd like to test the case of multiple registered clients receiving // We'd like to test the case of multiple registered clients receiving
// block epoch notifications. // block epoch notifications.
const numBlocks = 10 const numBlocks = 10
const numNtfns = numBlocks + 1 const numNtfns = numBlocks + 1
const numClients = 5 const numClients = 5
@ -403,6 +402,7 @@ func testBlockEpochNotification(miner *rpctest.Harness,
// expect each client to receive 11 notifications, one for the current // expect each client to receive 11 notifications, one for the current
// tip of the chain, and one for each of the ten blocks we generate // tip of the chain, and one for each of the ten blocks we generate
// below. So we'll use a WaitGroup to synchronize the test. // below. So we'll use a WaitGroup to synchronize the test.
clientErrors := make(chan error, numClients)
for i := 0; i < numClients; i++ { for i := 0; i < numClients; i++ {
epochClient, err := notifier.RegisterBlockEpochNtfn(nil) epochClient, err := notifier.RegisterBlockEpochNtfn(nil)
if err != nil { if err != nil {
@ -412,7 +412,24 @@ func testBlockEpochNotification(miner *rpctest.Harness,
wg.Add(numNtfns) wg.Add(numNtfns)
go func() { go func() {
for i := 0; i < numNtfns; i++ { for i := 0; i < numNtfns; i++ {
<-epochClient.Epochs // Ensure that each block epoch has a header,
// and that header matches the contained header
// hash.
blockEpoch := <-epochClient.Epochs
if blockEpoch.BlockHeader == nil {
fmt.Println(i)
clientErrors <- fmt.Errorf("block " +
"header is nil")
return
}
if blockEpoch.BlockHeader.BlockHash() !=
*blockEpoch.Hash {
clientErrors <- fmt.Errorf("block " +
"header hash mismatch")
return
}
wg.Done() wg.Done()
} }
}() }()
@ -431,6 +448,8 @@ func testBlockEpochNotification(miner *rpctest.Harness,
} }
select { select {
case err := <-clientErrors:
t.Fatalf("block epoch case failed: %v", err)
case <-epochsSent: case <-epochsSent:
case <-time.After(30 * time.Second): case <-time.After(30 * time.Second):
t.Fatalf("all notifications not sent") t.Fatalf("all notifications not sent")