multi: fix newly detected linter issues
This commit is contained in:
30 files changed
+106
-118
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
)
|
||||
@@ -22,6 +23,8 @@ const (
|
||||
type feeService struct {
|
||||
feeEstimates
|
||||
|
||||
t *testing.T
|
||||
|
||||
srv *http.Server
|
||||
wg sync.WaitGroup
|
||||
|
||||
@@ -36,9 +39,10 @@ type feeEstimates struct {
|
||||
}
|
||||
|
||||
// startFeeService spins up a go-routine to serve fee estimates.
|
||||
func startFeeService() *feeService {
|
||||
func startFeeService(t *testing.T) *feeService {
|
||||
port := NextAvailablePort()
|
||||
f := feeService{
|
||||
t: t,
|
||||
url: fmt.Sprintf("http://localhost:%v/fee-estimates.json", port),
|
||||
}
|
||||
|
||||
@@ -59,7 +63,7 @@ func startFeeService() *feeService {
|
||||
defer f.wg.Done()
|
||||
|
||||
if err := f.srv.ListenAndServe(); err != http.ErrServerClosed {
|
||||
fmt.Printf("error: cannot start fee api: %v", err)
|
||||
f.t.Errorf("error: cannot start fee api: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -73,23 +77,21 @@ func (f *feeService) handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
bytes, err := json.Marshal(f.feeEstimates)
|
||||
if err != nil {
|
||||
fmt.Printf("error: cannot serialize "+
|
||||
"estimates: %v", err)
|
||||
f.t.Errorf("error: cannot serialize estimates: %v", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
_, err = io.WriteString(w, string(bytes))
|
||||
if err != nil {
|
||||
fmt.Printf("error: cannot send estimates: %v",
|
||||
err)
|
||||
f.t.Errorf("error: cannot send estimates: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// stop stops the web server.
|
||||
func (f *feeService) stop() {
|
||||
if err := f.srv.Shutdown(context.Background()); err != nil {
|
||||
fmt.Printf("error: cannot stop fee api: %v", err)
|
||||
f.t.Errorf("error: cannot stop fee api: %v", err)
|
||||
}
|
||||
|
||||
f.wg.Wait()
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// TestFeeService tests the itest fee estimating web service.
|
||||
func TestFeeService(t *testing.T) {
|
||||
service := startFeeService()
|
||||
service := startFeeService(t)
|
||||
defer service.stop()
|
||||
|
||||
service.setFee(5000)
|
||||
|
||||
@@ -96,8 +96,6 @@ type NetworkHarness struct {
|
||||
func NewNetworkHarness(m *HarnessMiner, b BackendConfig, lndBinary string,
|
||||
dbBackend DatabaseBackend) (*NetworkHarness, error) {
|
||||
|
||||
feeService := startFeeService()
|
||||
|
||||
ctxt, cancel := context.WithCancel(context.Background())
|
||||
|
||||
n := NetworkHarness{
|
||||
@@ -107,7 +105,6 @@ func NewNetworkHarness(m *HarnessMiner, b BackendConfig, lndBinary string,
|
||||
netParams: m.ActiveNet,
|
||||
Miner: m,
|
||||
BackendCfg: b,
|
||||
feeService: feeService,
|
||||
runCtx: ctxt,
|
||||
cancel: cancel,
|
||||
lndBinary: lndBinary,
|
||||
@@ -150,6 +147,7 @@ func (n *NetworkHarness) SetUp(t *testing.T,
|
||||
fakeLogger := grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard)
|
||||
grpclog.SetLoggerV2(fakeLogger)
|
||||
n.currentTestCase = testCase
|
||||
n.feeService = startFeeService(t)
|
||||
|
||||
// Start the initial seeder nodes within the test network, then connect
|
||||
// their respective RPC clients.
|
||||
|
||||
+12
-12
@@ -228,7 +228,7 @@ func (cfg *BaseNodeConfig) GenArgs() []string {
|
||||
fmt.Sprintf("--invoicemacaroonpath=%v", cfg.InvoiceMacPath),
|
||||
fmt.Sprintf("--trickledelay=%v", trickleDelay),
|
||||
fmt.Sprintf("--profile=%d", cfg.ProfilePort),
|
||||
fmt.Sprintf("--caches.rpc-graph-cache-duration=0"),
|
||||
fmt.Sprintf("--caches.rpc-graph-cache-duration=%d", 0),
|
||||
}
|
||||
args = append(args, nodeArgs...)
|
||||
|
||||
@@ -988,9 +988,9 @@ func (hn *HarnessNode) FetchNodeInfo() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddToLog adds a line of choice to the node's logfile. This is useful
|
||||
// AddToLogf adds a line of choice to the node's logfile. This is useful
|
||||
// to interleave test output with output from the node.
|
||||
func (hn *HarnessNode) AddToLog(format string, a ...interface{}) {
|
||||
func (hn *HarnessNode) AddToLogf(format string, a ...interface{}) {
|
||||
// If this node was not set up with a log file, just return early.
|
||||
if hn.logFile == nil {
|
||||
return
|
||||
@@ -998,7 +998,7 @@ func (hn *HarnessNode) AddToLog(format string, a ...interface{}) {
|
||||
|
||||
desc := fmt.Sprintf("itest: %s\n", fmt.Sprintf(format, a...))
|
||||
if _, err := hn.logFile.WriteString(desc); err != nil {
|
||||
hn.PrintErr("write to log err: %v", err)
|
||||
hn.PrintErrf("write to log err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1281,7 +1281,7 @@ func (hn *HarnessNode) lightningNetworkWatcher() {
|
||||
err := hn.receiveTopologyClientStream(graphUpdates)
|
||||
|
||||
if err != nil {
|
||||
hn.PrintErr("receive topology client stream "+
|
||||
hn.PrintErrf("receive topology client stream "+
|
||||
"got err:%v", err)
|
||||
}
|
||||
}()
|
||||
@@ -1505,9 +1505,9 @@ func (hn *HarnessNode) WaitForBalance(expectedBalance btcutil.Amount,
|
||||
return nil
|
||||
}
|
||||
|
||||
// PrintErr prints an error to the console.
|
||||
func (hn *HarnessNode) PrintErr(format string, a ...interface{}) {
|
||||
fmt.Printf("itest error from [node:%s]: %s\n",
|
||||
// PrintErrf prints an error to the console.
|
||||
func (hn *HarnessNode) PrintErrf(format string, a ...interface{}) {
|
||||
fmt.Printf("itest error from [node:%s]: %s\n", // nolint:forbidigo
|
||||
hn.Cfg.Name, fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
@@ -1521,7 +1521,7 @@ func (hn *HarnessNode) handleChannelEdgeUpdates(
|
||||
for _, newChan := range updates {
|
||||
op, err := MakeOutpoint(newChan.ChanPoint)
|
||||
if err != nil {
|
||||
hn.PrintErr("failed to create outpoint for %v "+
|
||||
hn.PrintErrf("failed to create outpoint for %v "+
|
||||
"got err: %v", newChan.ChanPoint, err)
|
||||
return
|
||||
}
|
||||
@@ -1607,7 +1607,7 @@ func (hn *HarnessNode) handleClosedChannelUpdate(
|
||||
for _, closedChan := range updates {
|
||||
op, err := MakeOutpoint(closedChan.ChanPoint)
|
||||
if err != nil {
|
||||
hn.PrintErr("failed to create outpoint for %v "+
|
||||
hn.PrintErrf("failed to create outpoint for %v "+
|
||||
"got err: %v", closedChan.ChanPoint, err)
|
||||
return
|
||||
}
|
||||
@@ -1775,7 +1775,7 @@ func (hn *HarnessNode) getChannelPolicies(include bool) policyUpdateMap {
|
||||
IncludeUnannounced: include,
|
||||
})
|
||||
if err != nil {
|
||||
hn.PrintErr("DescribeGraph got err: %v", err)
|
||||
hn.PrintErrf("DescribeGraph got err: %v", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1813,7 +1813,7 @@ func (hn *HarnessNode) getChannelPolicies(include bool) policyUpdateMap {
|
||||
func renameFile(fromFileName, toFileName string) {
|
||||
err := os.Rename(fromFileName, toFileName)
|
||||
if err != nil {
|
||||
fmt.Printf("could not rename %s to %s: %v\n",
|
||||
fmt.Printf("could not rename %s to %s: %v\n", // nolint:forbidigo
|
||||
fromFileName, toFileName, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1626,9 +1626,7 @@ func getSpendingTxInMempool(t *harnessTest, miner *rpcclient.Client,
|
||||
|
||||
for _, txIn := range msgTx.TxIn {
|
||||
input := txIn.PreviousOutPoint
|
||||
if _, ok := inputSet[input]; ok {
|
||||
delete(inputSet, input)
|
||||
}
|
||||
delete(inputSet, input)
|
||||
}
|
||||
|
||||
if len(inputSet) > 0 {
|
||||
|
||||
@@ -69,6 +69,9 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
||||
ctxb := context.Background()
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "etcd")
|
||||
if err != nil {
|
||||
ht.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
etcdCfg, cleanup, err := kvdb.StartEtcdTestBackend(
|
||||
tmpDir, uint16(lntest.NextAvailablePort()),
|
||||
uint16(lntest.NextAvailablePort()), "",
|
||||
@@ -100,6 +103,9 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
||||
|
||||
ctxt, _ := context.WithTimeout(ctxb, defaultTimeout)
|
||||
info1, err := carol1.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||
if err != nil {
|
||||
ht.Fatalf("unable to get info: %v", err)
|
||||
}
|
||||
|
||||
net.ConnectNodes(ht.t, carol1, net.Alice)
|
||||
|
||||
@@ -172,6 +178,9 @@ func testEtcdFailoverCase(net *lntest.NetworkHarness, ht *harnessTest,
|
||||
|
||||
// Make sure Carol-1 and Carol-2 have the same identity.
|
||||
info2, err := carol2.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||
if err != nil {
|
||||
ht.Fatalf("unable to get info: %v", err)
|
||||
}
|
||||
if info1.IdentityPubkey != info2.IdentityPubkey {
|
||||
ht.Fatalf("Carol-1 and Carol-2 must have the same identity: "+
|
||||
"%v vs %v", info1.IdentityPubkey, info2.IdentityPubkey)
|
||||
|
||||
@@ -139,7 +139,7 @@ test:
|
||||
"---- basic channel funding subtest %s ----\n",
|
||||
testName,
|
||||
)
|
||||
net.Alice.AddToLog(logLine)
|
||||
net.Alice.AddToLogf(logLine)
|
||||
|
||||
success := t.t.Run(testName, func(t *testing.T) {
|
||||
testFunding(cc, dc)
|
||||
|
||||
@@ -99,7 +99,7 @@ func testMultiHopHtlcClaims(net *lntest.NetworkHarness, t *harnessTest) {
|
||||
"%s/%s ----\n",
|
||||
testName, subTest.name,
|
||||
)
|
||||
net.Alice.AddToLog(logLine)
|
||||
net.Alice.AddToLogf(logLine)
|
||||
|
||||
success := ht.t.Run(subTest.name, func(t *testing.T) {
|
||||
ht := newHarnessTest(t, net)
|
||||
|
||||
@@ -232,8 +232,8 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
||||
testCase.name,
|
||||
)
|
||||
|
||||
lndHarness.Alice.AddToLog(logLine)
|
||||
lndHarness.Bob.AddToLog(logLine)
|
||||
lndHarness.Alice.AddToLogf(logLine)
|
||||
lndHarness.Bob.AddToLogf(logLine)
|
||||
|
||||
// Start every test with the default static fee estimate.
|
||||
lndHarness.SetFeeEstimate(12500)
|
||||
|
||||
Reference in new issue
Block a user