Remove 1.8 and 1.9 tests. Updated failfast test

pull/943/head
ariley 2020-05-04 19:47:19 +01:00 committed by Boyan Soubachov
parent 93bea66f75
commit f96052c82a
2 changed files with 20 additions and 7 deletions

View File

@ -4,8 +4,6 @@ sudo: false
matrix: matrix:
include: include:
- go: "1.8.x"
- go: "1.9.x"
- go: "1.10.x" - go: "1.10.x"
- go: "1.11.x" - go: "1.11.x"
env: GO111MODULE=off env: GO111MODULE=off
@ -28,4 +26,3 @@ script:
- ./.travis.gofmt.sh - ./.travis.gofmt.sh
- ./.travis.govet.sh - ./.travis.govet.sh
- go test -v -race ./... - go test -v -race ./...
- go test -v -race -failfast -run TestSuiteWithFailfast

View File

@ -1,11 +1,13 @@
package suite package suite
import ( import (
"bytes"
"errors" "errors"
"flag" "flag"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
"os/exec"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -525,14 +527,15 @@ func (s *FailfastSuite) call(method string) {
s.callOrder = append(s.callOrder, method) s.callOrder = append(s.callOrder, method)
} }
func TestSuiteWithFailfast(t *testing.T) { func TestFailfastSuite(t *testing.T) {
// This test suite is run twice by travis. Once normally and once with the -failfast flag // 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) failFast := flag.Lookup("test.failfast").Value.(flag.Getter).Get().(bool)
s := new(FailfastSuite) s := new(FailfastSuite)
ok := testing.RunTests( ok := testing.RunTests(
allTestsFilter, allTestsFilter,
[]testing.InternalTest{{ []testing.InternalTest{{
Name: "TestSuiteWithFailfast", Name: "TestFailfastSuite",
F: func(t *testing.T) { F: func(t *testing.T) {
Run(t, s) Run(t, s)
}, },
@ -540,13 +543,26 @@ func TestSuiteWithFailfast(t *testing.T) {
) )
assert.Equal(t, false, ok) assert.Equal(t, false, ok)
if failFast { 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, ";")) assert.Equal(t, "SetupSuite;SetupTest;Test A Fails;TearDownTest;TearDownSuite", strings.Join(s.callOrder, ";"))
} else { } else {
// Test A Fails and because we are running without failfast we continue and run Test B and then proceed to TearDownSuite // 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, ";")) 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() { func (s *FailfastSuite) SetupSuite() {
s.call("SetupSuite") s.call("SetupSuite")
} }