mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
chainntnfs/test: add new test assertion to ensure block epoch headers set
This commit is contained in:
parent
67aa7a0df7
commit
0d8ffd95dd
1 changed files with 21 additions and 2 deletions
|
@ -393,7 +393,6 @@ func testBlockEpochNotification(miner *rpctest.Harness,
|
|||
|
||||
// We'd like to test the case of multiple registered clients receiving
|
||||
// block epoch notifications.
|
||||
|
||||
const numBlocks = 10
|
||||
const numNtfns = numBlocks + 1
|
||||
const numClients = 5
|
||||
|
@ -403,6 +402,7 @@ func testBlockEpochNotification(miner *rpctest.Harness,
|
|||
// 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
|
||||
// below. So we'll use a WaitGroup to synchronize the test.
|
||||
clientErrors := make(chan error, numClients)
|
||||
for i := 0; i < numClients; i++ {
|
||||
epochClient, err := notifier.RegisterBlockEpochNtfn(nil)
|
||||
if err != nil {
|
||||
|
@ -412,7 +412,24 @@ func testBlockEpochNotification(miner *rpctest.Harness,
|
|||
wg.Add(numNtfns)
|
||||
go func() {
|
||||
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()
|
||||
}
|
||||
}()
|
||||
|
@ -431,6 +448,8 @@ func testBlockEpochNotification(miner *rpctest.Harness,
|
|||
}
|
||||
|
||||
select {
|
||||
case err := <-clientErrors:
|
||||
t.Fatalf("block epoch case failed: %v", err)
|
||||
case <-epochsSent:
|
||||
case <-time.After(30 * time.Second):
|
||||
t.Fatalf("all notifications not sent")
|
||||
|
|
Loading…
Add table
Reference in a new issue