Skip to content

Commit

Permalink
Remove 1.8 and 1.9 tests. Updated failfast test
Browse files Browse the repository at this point in the history
  • Loading branch information
AdRiley authored and boyan-soubachov committed May 4, 2020
1 parent 93bea66 commit f96052c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ sudo: false

matrix:
include:
- go: "1.8.x"
- go: "1.9.x"
- go: "1.10.x"
- go: "1.11.x"
env: GO111MODULE=off
Expand All @@ -28,4 +26,3 @@ script:
- ./.travis.gofmt.sh
- ./.travis.govet.sh
- go test -v -race ./...
- go test -v -race -failfast -run TestSuiteWithFailfast
24 changes: 20 additions & 4 deletions suite/suite_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package suite

import (
"bytes"
"errors"
"flag"
"io/ioutil"
"math/rand"
"os"
"os/exec"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -525,28 +527,42 @@ func (s *FailfastSuite) call(method string) {
s.callOrder = append(s.callOrder, method)
}

func TestSuiteWithFailfast(t *testing.T) {
// This test suite is run twice by travis. Once normally and once with the -failfast flag
func TestFailfastSuite(t *testing.T) {
// This test suite is run twice. Once normally and once with the -failfast flag by TestFailfastSuiteFailFastOn
// If you need to debug it run this test directly with the failfast flag set on/off as you need
failFast := flag.Lookup("test.failfast").Value.(flag.Getter).Get().(bool)
s := new(FailfastSuite)
ok := testing.RunTests(
allTestsFilter,
[]testing.InternalTest{{
Name: "TestSuiteWithFailfast",
Name: "TestFailfastSuite",
F: func(t *testing.T) {
Run(t, s)
},
}},
)
assert.Equal(t, false, ok)
if failFast {
// Test A Fails and because we are running with failfast Test B never runs and we proceed staright to TearDownSuite
// Test A Fails and because we are running with failfast Test B never runs and we proceed straight to TearDownSuite
assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";"))
} else {
// Test A Fails and because we are running without failfast we continue and run Test B and then proceed to TearDownSuite
assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;SetupTest;Test B Passes;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";"))
}
}
func TestFailfastSuiteFailFastOn(t *testing.T) {
// To test this with failfast on (and isolated from other intended test failures in our test suite) we launch it in its own process
cmd := exec.Command("go", "test", "-v", "-race", "-run", "TestFailfastSuite", "-failfast")
var out bytes.Buffer
cmd.Stdout = &out
t.Log("Running go test -v -race -run TestFailfastSuite -failfast")
err := cmd.Run()
t.Log(out.String())
if err != nil {
t.Log(err)
t.Fail()
}
}
func (s *FailfastSuite) SetupSuite() {
s.call("SetupSuite")
}
Expand Down

0 comments on commit f96052c

Please sign in to comment.