Merge pull request #577 from halseth/test-log-testcase-start
Add integration test case name to node output
This commit is contained in:
commit
a3f2bdebbf
@ -4847,6 +4847,15 @@ func TestLightningNetworkDaemon(t *testing.T) {
|
|||||||
|
|
||||||
t.Logf("Running %v integration tests", len(testsCases))
|
t.Logf("Running %v integration tests", len(testsCases))
|
||||||
for _, testCase := range testsCases {
|
for _, testCase := range testsCases {
|
||||||
|
logLine := fmt.Sprintf("STARTING ============ %v ============\n",
|
||||||
|
testCase.name)
|
||||||
|
if err := lndHarness.Alice.AddToLog(logLine); err != nil {
|
||||||
|
t.Fatalf("unable to add to log: %v", err)
|
||||||
|
}
|
||||||
|
if err := lndHarness.Bob.AddToLog(logLine); err != nil {
|
||||||
|
t.Fatalf("unable to add to log: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
success := t.Run(testCase.name, func(t1 *testing.T) {
|
success := t.Run(testCase.name, func(t1 *testing.T) {
|
||||||
ht := newHarnessTest(t1)
|
ht := newHarnessTest(t1)
|
||||||
ht.RunTestCase(testCase, lndHarness)
|
ht.RunTestCase(testCase, lndHarness)
|
||||||
|
@ -163,6 +163,7 @@ type HarnessNode struct {
|
|||||||
|
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
pidFile string
|
pidFile string
|
||||||
|
logFile *os.File
|
||||||
|
|
||||||
// processExit is a channel that's closed once it's detected that the
|
// processExit is a channel that's closed once it's detected that the
|
||||||
// process this instance of HarnessNode is bound to has exited.
|
// process this instance of HarnessNode is bound to has exited.
|
||||||
@ -231,10 +232,10 @@ func (hn *HarnessNode) start(lndError chan<- error) error {
|
|||||||
// If the logoutput flag is passed, redirect output from the nodes to
|
// If the logoutput flag is passed, redirect output from the nodes to
|
||||||
// log files.
|
// log files.
|
||||||
if *logOutput {
|
if *logOutput {
|
||||||
logFile := fmt.Sprintf("output%d.log", hn.NodeID)
|
fileName := fmt.Sprintf("output%d.log", hn.NodeID)
|
||||||
|
|
||||||
// Create file if not exists, otherwise append.
|
// Create file if not exists, otherwise append.
|
||||||
file, err := os.OpenFile(logFile,
|
file, err := os.OpenFile(fileName,
|
||||||
os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -246,6 +247,10 @@ func (hn *HarnessNode) start(lndError chan<- error) error {
|
|||||||
|
|
||||||
// Pass the node's stdout only to the file.
|
// Pass the node's stdout only to the file.
|
||||||
hn.cmd.Stdout = file
|
hn.cmd.Stdout = file
|
||||||
|
|
||||||
|
// Let the node keep a reference to this file, such
|
||||||
|
// that we can add to it if necessary.
|
||||||
|
hn.logFile = file
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := hn.cmd.Start(); err != nil {
|
if err := hn.cmd.Start(); err != nil {
|
||||||
@ -304,6 +309,19 @@ func (hn *HarnessNode) start(lndError chan<- error) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddToLog 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(line string) error {
|
||||||
|
// If this node was not set up with a log file, just return early.
|
||||||
|
if hn.logFile == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if _, err := hn.logFile.WriteString(line); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// writePidFile writes the process ID of the running lnd process to a .pid file.
|
// writePidFile writes the process ID of the running lnd process to a .pid file.
|
||||||
func (hn *HarnessNode) writePidFile() error {
|
func (hn *HarnessNode) writePidFile() error {
|
||||||
filePath := filepath.Join(hn.cfg.BaseDir, fmt.Sprintf("%v.pid", hn.NodeID))
|
filePath := filepath.Join(hn.cfg.BaseDir, fmt.Sprintf("%v.pid", hn.NodeID))
|
||||||
|
Loading…
Reference in New Issue
Block a user