Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add logging to libgoal fixture on failure #4384

Merged
merged 8 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/framework/fixtures/libgoalFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package fixtures

import (
"bufio"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -311,6 +312,10 @@ func (f *LibGoalFixture) ShutdownImpl(preserveData bool) {
f.NC.StopKMD()
if preserveData {
f.network.Stop(f.binDir)
f.dumpLogs(filepath.Join(f.PrimaryDataDir(), "node.log"))
for _, nodeDir := range f.NodeDataDirs() {
f.dumpLogs(filepath.Join(nodeDir, "node.log"))
}
} else {
f.network.Delete(f.binDir)

Expand All @@ -324,6 +329,24 @@ func (f *LibGoalFixture) ShutdownImpl(preserveData bool) {
}
}

// dumpLogs prints out log files for the running nodes
func (f *LibGoalFixture) dumpLogs(filePath string) {
file, err := os.Open(filePath)
if err != nil {
f.t.Logf("could not open %s", filePath)
return
}
defer file.Close()

f.t.Log("=================================\n")
parts := strings.Split(filePath, "/")
f.t.Logf("%s/%s:", parts[len(parts)-2], parts[len(parts)-1]) // Primary/node.log
scanner := bufio.NewScanner(file)
for scanner.Scan() {
f.t.Logf(scanner.Text())
}
}

// intercept baseFixture.failOnError so we can clean up any algods that are still alive
func (f *LibGoalFixture) failOnError(err error, message string) {
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions test/framework/fixtures/restClientFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ func (f *RestClientFixture) WaitForAllTxnsToConfirm(roundTimeout uint64, txidsAn
for txid, addr := range txidsAndAddresses {
_, err := f.WaitForConfirmedTxn(roundTimeout, addr, txid)
if err != nil {
f.t.Logf("txn failed to confirm: ", addr, txid)
pendingTxns, err := f.AlgodClient.GetPendingTransactions(0)
if err == nil {
pendingTxids := make([]string, 0, pendingTxns.TotalTxns)
for _, txn := range pendingTxns.TruncatedTxns.Transactions {
pendingTxids = append(pendingTxids, txn.TxID)
}
f.t.Logf("pending txids: ", pendingTxids)
} else {
f.t.Logf("unable to log pending txns, ", err)
}
allTxids := make([]string, 0, len(txidsAndAddresses))
for txID := range txidsAndAddresses {
allTxids = append(allTxids, txID)
}
f.t.Logf("all txids: ", allTxids)
return false
}
}
Expand Down