Merge pull request #4577 from yyforyongyu/itest-better-logging
itest: logging for subtests and refactor WaitForBlockchainSync
This commit is contained in:
5 files changed
+57
-45
No files matched your search
@@ -0,0 +1,16 @@
|
|||||||
|
package itest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/lntest"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AddToNodeLog adds a line to the log file and asserts there's no error.
|
||||||
|
func AddToNodeLog(t *testing.T,
|
||||||
|
node *lntest.HarnessNode, logLine string) {
|
||||||
|
|
||||||
|
err := node.AddToLog(logLine)
|
||||||
|
require.NoError(t, err, "unable to add to log")
|
||||||
|
}
|
||||||
@@ -137,6 +137,12 @@ test:
|
|||||||
"carol_commit=%v,dave_commit=%v", cc, dc,
|
"carol_commit=%v,dave_commit=%v", cc, dc,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logLine := fmt.Sprintf(
|
||||||
|
"---- basic channel funding subtest %s ----\n",
|
||||||
|
testName,
|
||||||
|
)
|
||||||
|
AddToNodeLog(t.t, net.Alice, logLine)
|
||||||
|
|
||||||
success := t.t.Run(testName, func(t *testing.T) {
|
success := t.t.Run(testName, func(t *testing.T) {
|
||||||
testFunding(cc, dc)
|
testFunding(cc, dc)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -102,6 +102,13 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
for _, subTest := range subTests {
|
for _, subTest := range subTests {
|
||||||
subTest := subTest
|
subTest := subTest
|
||||||
|
|
||||||
|
logLine := fmt.Sprintf(
|
||||||
|
"---- multi-hop htlc subtest "+
|
||||||
|
"%s/%s ----\n",
|
||||||
|
testName, subTest.name,
|
||||||
|
)
|
||||||
|
AddToNodeLog(t, net.Alice, logLine)
|
||||||
|
|
||||||
success := ht.t.Run(subTest.name, func(t *testing.T) {
|
success := ht.t.Run(subTest.name, func(t *testing.T) {
|
||||||
ht := newHarnessTest(t, net)
|
ht := newHarnessTest(t, net)
|
||||||
|
|
||||||
|
|||||||
@@ -3153,6 +3153,11 @@ func testChannelForceClosure(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
for _, channelType := range commitTypes {
|
for _, channelType := range commitTypes {
|
||||||
testName := fmt.Sprintf("committype=%v", channelType)
|
testName := fmt.Sprintf("committype=%v", channelType)
|
||||||
|
logLine := fmt.Sprintf(
|
||||||
|
"---- channel force close subtest %s ----\n",
|
||||||
|
testName,
|
||||||
|
)
|
||||||
|
AddToNodeLog(t.t, net.Alice, logLine)
|
||||||
|
|
||||||
channelType := channelType
|
channelType := channelType
|
||||||
success := t.t.Run(testName, func(t *testing.T) {
|
success := t.t.Run(testName, func(t *testing.T) {
|
||||||
@@ -14476,11 +14481,8 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
|||||||
testCase.name,
|
testCase.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
err = lndHarness.Alice.AddToLog(logLine)
|
AddToNodeLog(t, lndHarness.Alice, logLine)
|
||||||
require.NoError(t1, err, "unable to add to log")
|
AddToNodeLog(t, lndHarness.Bob, logLine)
|
||||||
|
|
||||||
err = lndHarness.Bob.AddToLog(logLine)
|
|
||||||
require.NoError(t1, err, "unable to add to log")
|
|
||||||
|
|
||||||
// Start every test with the default static fee estimate.
|
// Start every test with the default static fee estimate.
|
||||||
lndHarness.SetFeeEstimate(12500)
|
lndHarness.SetFeeEstimate(12500)
|
||||||
|
|||||||
+21
-40
@@ -1304,50 +1304,31 @@ func (hn *HarnessNode) WaitForNetworkChannelClose(ctx context.Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitForBlockchainSync will block until the target nodes has fully
|
// WaitForBlockchainSync waits for the target node to be fully synchronized with
|
||||||
// synchronized with the blockchain. If the passed context object has a set
|
// the blockchain. If the passed context object has a set timeout, it will
|
||||||
// timeout, then the goroutine will continually poll until the timeout has
|
// continually poll until the timeout has elapsed. In the case that the chain
|
||||||
// elapsed. In the case that the chain isn't synced before the timeout is up,
|
// isn't synced before the timeout is up, this function will return an error.
|
||||||
// then this function will return an error.
|
|
||||||
func (hn *HarnessNode) WaitForBlockchainSync(ctx context.Context) error {
|
func (hn *HarnessNode) WaitForBlockchainSync(ctx context.Context) error {
|
||||||
errChan := make(chan error, 1)
|
ticker := time.NewTicker(time.Millisecond * 100)
|
||||||
retryDelay := time.Millisecond * 100
|
defer ticker.Stop()
|
||||||
|
|
||||||
go func() {
|
for {
|
||||||
for {
|
resp, err := hn.GetInfo(ctx, &lnrpc.GetInfoRequest{})
|
||||||
select {
|
if err != nil {
|
||||||
case <-ctx.Done():
|
return err
|
||||||
case <-hn.quit:
|
}
|
||||||
return
|
if resp.SyncedToChain {
|
||||||
default:
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
getInfoReq := &lnrpc.GetInfoRequest{}
|
|
||||||
getInfoResp, err := hn.GetInfo(ctx, getInfoReq)
|
|
||||||
if err != nil {
|
|
||||||
errChan <- err
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if getInfoResp.SyncedToChain {
|
|
||||||
errChan <- nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return
|
|
||||||
case <-time.After(retryDelay):
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-hn.quit:
|
case <-ctx.Done():
|
||||||
return nil
|
return fmt.Errorf("timeout while waiting for " +
|
||||||
case err := <-errChan:
|
"blockchain sync")
|
||||||
return err
|
case <-hn.quit:
|
||||||
case <-ctx.Done():
|
return nil
|
||||||
return fmt.Errorf("timeout while waiting for blockchain sync")
|
case <-ticker.C:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user