Skip to content

Commit

Permalink
Merge pull request #238 from euanh/fix-test-integration-jenkins
Browse files Browse the repository at this point in the history
Fix test integration jenkins
  • Loading branch information
ehazlett authored Jan 8, 2019
2 parents b83b971 + 356361e commit 0abb628
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test-integration: rttf image $(EXTENSIONS)
@go test -timeout $(TEST_INTEGRATION_TIMEOUT) -v $(TEST_ARGS) ./test/integration/deploy/...

test-integration-jenkins: image $(EXTENSIONS)
@2>&1 go test -timeout $(TEST_INTEGRATION_TIMEOUT) -v $(TEST_ARGS) ./test/integration/... | go2xunit -output tests-integration.xml
@2>&1 go test -timeout $(TEST_INTEGRATION_TIMEOUT) -v $(TEST_ARGS) ./test/integration/deploy/... | go2xunit -output tests-integration.xml

check-integration-env:
@if [ -z $(TEST_INTEGRATION_EXTENSION) ]; then echo 'Please set the environment variable TEST_INTEGRATION_EXTENSION for the desired extension' && exit 1; fi
Expand Down
63 changes: 6 additions & 57 deletions test/integration/common/common.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package common

import (
"bufio"
"context"
"fmt"
"os"
"os/exec"
"strings"
"testing"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/interlock/test/integration"
"github.com/docker/interlock/test/integration/config"
)
Expand Down Expand Up @@ -188,11 +183,9 @@ func (c *Common) RunInterlockRttf(t *testing.T, suiteName string) {
t.Fatal(err.Error())
}

respID, _, err := OsExec([]string{
"docker",
cmd := exec.Command("docker",
"run",
"--rm",
"-d",
"-e", fmt.Sprintf("TEST_INTEGRATION_SERVICE_WAIT_TIMEOUT=%s", os.Getenv("TEST_INTEGRATION_SERVICE_WAIT_TIMEOUT")),
"-e", fmt.Sprintf("TEST_INTEGRATION_SERVICE_TEST_TIMEOUT=%s", os.Getenv("TEST_INTEGRATION_SERVICE_TEST_TIMEOUT")),
"-e", fmt.Sprintf("TEST_INTEGRATION_EXTENSION=%s", os.Getenv("TEST_INTEGRATION_EXTENSION")),
Expand All @@ -204,56 +197,12 @@ func (c *Common) RunInterlockRttf(t *testing.T, suiteName string) {
"--network", c.testCluster.NetworkName(),
config.TestRttfImage,
"run.test", "-test.v",
})
if err != nil {
t.Fatal(err.Error())
}
)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

// We use a containerAttach call using a docker client here to ensure that logs are continuously outputted
dockerClient, err := client.NewEnvClient()
err = cmd.Run()
if err != nil {
t.Fatal(err.Error())
}
attachResp, err := dockerClient.ContainerAttach(context.TODO(), respID, types.ContainerAttachOptions{
Stream: true,
Stdin: true,
Stdout: true,
Stderr: true,
})

if err != nil {
t.Fatal(err.Error())
}
rd := bufio.NewReader(attachResp.Reader)

go func() {
fmt.Printf("reading logs from container %s\n", respID)
_, err = stdcopy.StdCopy(os.Stdout, os.Stderr, rd)
if err != nil {
t.Fatalf("Unable to read logs from container: %s\n", err)
}
}()
var exitCode int64
for i := 0; i < runContainerRetries; i++ {
resC, errC := dockerClient.ContainerWait(context.TODO(), respID, container.WaitConditionNotRunning)
select {
case res := <-resC:
exitCode = res.StatusCode
err = nil
case err = <-errC:
exitCode = -1
if strings.Contains(err.Error(), "Cannot connect to the Docker daemon") {
time.Sleep(1 * time.Second)
continue
}
err = fmt.Errorf("error while waiting for the rttf: %s", err)
}
break // Either got an exitCode or an unexpected error.
}
if err != nil {
t.Fatalf("encountered error while running the rttf image: %s", err.Error())
}
if exitCode != int64(0) {
t.Fatalf("interlock-rttf suite completed with non-zero error code: %d\n", exitCode)
}
}
2 changes: 1 addition & 1 deletion test/integration/run/rttf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRunRttf(t *testing.T) {
}
fmt.Println("rttf setup complete")
suite := os.Getenv("TEST_INTEGRATION_SUITE")
fmt.Printf("Starting suite '%s'", suite)
fmt.Printf("Starting suite '%s'\n", suite)
switch suite {
case "standard":
Standard(t)
Expand Down

0 comments on commit 0abb628

Please sign in to comment.