Skip to content

Commit

Permalink
test/e2e: Add race detection in e2e tests (#5805)
Browse files Browse the repository at this point in the history
Compile contour binary with -race flag and look for "DATA RACE" in
stderr. Fails test if found.

Signed-off-by: Sunjay Bhatia <[email protected]>
  • Loading branch information
sunjayBhatia authored Oct 18, 2023
1 parent d53f2a3 commit d99ca25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions test/e2e/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/onsi/gomega/gexec"
Expand Down Expand Up @@ -696,6 +697,7 @@ func localAddress() string {
}

func (d *Deployment) StopLocalContour(contourCmd *gexec.Session, configFile string) error {
defer os.RemoveAll(configFile)

// Look for the ENV variable to tell if this test run should use
// the ContourConfiguration file or the ContourConfiguration CRD.
Expand All @@ -714,8 +716,11 @@ func (d *Deployment) StopLocalContour(contourCmd *gexec.Session, configFile stri

// Default timeout of 1s produces test flakes,
// a minute should be more than enough to avoid them.
contourCmd.Terminate().Wait(time.Minute)
return os.RemoveAll(configFile)
logs := contourCmd.Terminate().Wait(time.Minute).Err.Contents()
if strings.Contains(string(logs), "DATA RACE") {
return errors.New("Detected data race, see log output above to diagnose")
}
return nil
}

// Convenience method for deploying the pieces of the deployment needed for
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func NewFramework(inClusterTestSuite bool) *Framework {
}

var err error
contourBin, err = gexec.Build("github.com/projectcontour/contour/cmd/contour")
contourBin, err = gexec.Build("github.com/projectcontour/contour/cmd/contour", "-race")
require.NoError(t, err)
}

Expand Down

0 comments on commit d99ca25

Please sign in to comment.