integration: Log the instance output
This adds logging so that you can dig deeper into crashes or issues.
This commit is contained in:
@@ -41,6 +41,9 @@ func TestInstance0(t *testing.T) {
|
||||
}
|
||||
if err := m.SimpleDeployLang(code); err != nil {
|
||||
t.Errorf("failed with: %+v", err)
|
||||
if output, err := m.CombinedOutput(); err == nil {
|
||||
t.Errorf("logs from instance:\n\n%s", output)
|
||||
}
|
||||
return
|
||||
}
|
||||
d := m.Dir()
|
||||
@@ -98,6 +101,9 @@ func TestInstance1(t *testing.T) {
|
||||
|
||||
if !fail && err != nil {
|
||||
t.Errorf("failed with: %+v", err)
|
||||
if output, err := m.CombinedOutput(); err == nil {
|
||||
t.Errorf("logs from instance:\n\n%s", output)
|
||||
}
|
||||
return
|
||||
}
|
||||
if fail && err == nil {
|
||||
@@ -207,9 +213,15 @@ func TestCluster1(t *testing.T) {
|
||||
if d := c.Dir(); d != "" {
|
||||
t.Logf("test ran in:\n%s", d)
|
||||
}
|
||||
instances := c.Instances()
|
||||
|
||||
if !fail && err != nil {
|
||||
t.Errorf("failed with: %+v", err)
|
||||
for _, h := range hosts {
|
||||
if output, err := instances[h].CombinedOutput(); err == nil {
|
||||
t.Errorf("logs from instance `%s`:\n\n%s", h, output)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
if fail && err == nil {
|
||||
@@ -221,7 +233,6 @@ func TestCluster1(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
instances := c.Instances()
|
||||
for _, h := range hosts {
|
||||
instance := instances[h]
|
||||
d := instance.Dir()
|
||||
|
||||
@@ -46,6 +46,10 @@ const (
|
||||
// converged status tracking.
|
||||
ConvergedStatusFile = "csf.txt"
|
||||
|
||||
// StdoutStderrFile is the name of the file which is used for the
|
||||
// command output.
|
||||
StdoutStderrFile = "stdoutstderr.txt"
|
||||
|
||||
// longTimeout is a high bound of time we're willing to wait for events.
|
||||
// If we exceed this timeout, then it's likely we are blocked somewhere.
|
||||
longTimeout = 30 // seconds
|
||||
@@ -206,6 +210,15 @@ func (obj *Instance) Run(seeds []*Instance) error {
|
||||
fmt.Sprintf("MGMT_TEST_ROOT=%s", obj.testRootDirectory),
|
||||
}
|
||||
|
||||
// output file for storing logs
|
||||
file, err := os.Create(path.Join(obj.dir, StdoutStderrFile))
|
||||
if err != nil {
|
||||
return errwrap.Wrapf(err, "error creating log file")
|
||||
}
|
||||
defer file.Close()
|
||||
obj.cmd.Stdout = file
|
||||
obj.cmd.Stderr = file
|
||||
|
||||
if err := obj.cmd.Start(); err != nil {
|
||||
return errwrap.Wrapf(err, "error starting mgmt")
|
||||
}
|
||||
@@ -368,3 +381,12 @@ func (obj *Instance) DeployLang(code string) error {
|
||||
func (obj *Instance) Dir() string {
|
||||
return obj.dir
|
||||
}
|
||||
|
||||
// CombinedOutput returns the logged output from the instance.
|
||||
func (obj *Instance) CombinedOutput() (string, error) {
|
||||
contents, err := ioutil.ReadFile(path.Join(obj.dir, StdoutStderrFile))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(contents), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user