Merge pull request #18688 from hashicorp/f-resource-paralleltest

helper/resource: Add ParallelTest() function to allow opt-in acceptance testing concurrency with t.Parallel()
pull/18861/head
Brian Flad 8 years ago committed by GitHub
commit a47583d3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -418,6 +418,17 @@ func LogOutput(t TestT) (logOutput io.Writer, err error) {
return
}
// ParallelTest performs an acceptance test on a resource, allowing concurrency
// with other ParallelTest.
//
// Tests will fail if they do not properly handle conditions to allow multiple
// tests to occur against the same resource or service (e.g. random naming).
// All other requirements of the Test function also apply to this function.
func ParallelTest(t TestT, c TestCase) {
t.Parallel()
Test(t, c)
}
// Test performs an acceptance test on a resource.
//
// Tests are not run unless an environmental variable "TF_ACC" is
@ -1128,6 +1139,7 @@ type TestT interface {
Fatal(args ...interface{})
Skip(args ...interface{})
Name() string
Parallel()
}
// This is set to true by unit tests to alter some behavior

@ -45,6 +45,15 @@ func (p *resetProvider) TestReset() error {
return p.TestResetError
}
func TestParallelTest(t *testing.T) {
mt := new(mockT)
ParallelTest(mt, TestCase{})
if !mt.ParallelCalled {
t.Fatal("Parallel() not called")
}
}
func TestTest(t *testing.T) {
mp := &resetProvider{
MockResourceProvider: testProvider(),
@ -112,6 +121,9 @@ func TestTest(t *testing.T) {
if mt.failed() {
t.Fatalf("test failed: %s", mt.failMessage())
}
if mt.ParallelCalled {
t.Fatal("Parallel() called")
}
if !checkStep {
t.Fatal("didn't call check for step")
}
@ -692,12 +704,13 @@ func TestComposeTestCheckFunc(t *testing.T) {
// mockT implements TestT for testing
type mockT struct {
ErrorCalled bool
ErrorArgs []interface{}
FatalCalled bool
FatalArgs []interface{}
SkipCalled bool
SkipArgs []interface{}
ErrorCalled bool
ErrorArgs []interface{}
FatalCalled bool
FatalArgs []interface{}
ParallelCalled bool
SkipCalled bool
SkipArgs []interface{}
f bool
}
@ -714,6 +727,10 @@ func (t *mockT) Fatal(args ...interface{}) {
t.f = true
}
func (t *mockT) Parallel() {
t.ParallelCalled = true
}
func (t *mockT) Skip(args ...interface{}) {
t.SkipCalled = true
t.SkipArgs = args

Loading…
Cancel
Save