Tests for apply parallelism=1 and parallelism=2
This commit is contained in:
parent
fc60b2858c
commit
bf9c5c46d0
|
@ -58,6 +58,82 @@ func TestApply(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestApply_parallelism1(t *testing.T) {
|
||||
statePath := testTempFile(t)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
p := testProvider()
|
||||
pr := new(terraform.MockResourceProvisioner)
|
||||
|
||||
pr.ApplyFn = func(*terraform.InstanceState, *terraform.ResourceConfig) error {
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"-parallelism=1",
|
||||
testFixturePath("parallelism"),
|
||||
}
|
||||
|
||||
c := &ApplyCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfigWithShell(p, pr),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
elapsed := time.Since(start).Seconds()
|
||||
|
||||
// This test should take exactly two seconds, plus some minor amount of execution time.
|
||||
if elapsed < 2 || elapsed > 2.2 {
|
||||
t.Fatalf("bad: %f\n\n%s", elapsed, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestApply_parallelism2(t *testing.T) {
|
||||
statePath := testTempFile(t)
|
||||
|
||||
ui := new(cli.MockUi)
|
||||
p := testProvider()
|
||||
pr := new(terraform.MockResourceProvisioner)
|
||||
|
||||
pr.ApplyFn = func(*terraform.InstanceState, *terraform.ResourceConfig) error {
|
||||
time.Sleep(time.Second)
|
||||
return nil
|
||||
}
|
||||
|
||||
args := []string{
|
||||
"-state", statePath,
|
||||
"-parallelism=2",
|
||||
testFixturePath("parallelism"),
|
||||
}
|
||||
|
||||
c := &ApplyCommand{
|
||||
Meta: Meta{
|
||||
ContextOpts: testCtxConfigWithShell(p, pr),
|
||||
Ui: ui,
|
||||
},
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
if code := c.Run(args); code != 0 {
|
||||
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||
}
|
||||
elapsed := time.Since(start).Seconds()
|
||||
|
||||
// This test should take exactly one second, plus some minor amount of execution time.
|
||||
if elapsed < 1 || elapsed > 1.2 {
|
||||
t.Fatalf("bad: %f\n\n%s", elapsed, ui.ErrorWriter.String())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestApply_configInvalid(t *testing.T) {
|
||||
p := testProvider()
|
||||
ui := new(cli.MockUi)
|
||||
|
|
|
@ -52,6 +52,21 @@ func testCtxConfig(p terraform.ResourceProvider) *terraform.ContextOpts {
|
|||
}
|
||||
}
|
||||
|
||||
func testCtxConfigWithShell(p terraform.ResourceProvider, pr terraform.ResourceProvisioner) *terraform.ContextOpts {
|
||||
return &terraform.ContextOpts{
|
||||
Providers: map[string]terraform.ResourceProviderFactory{
|
||||
"test": func() (terraform.ResourceProvider, error) {
|
||||
return p, nil
|
||||
},
|
||||
},
|
||||
Provisioners: map[string]terraform.ResourceProvisionerFactory{
|
||||
"shell": func() (terraform.ResourceProvisioner, error) {
|
||||
return pr, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func testModule(t *testing.T, name string) *module.Tree {
|
||||
mod, err := module.NewTreeModule("", filepath.Join(fixtureDir, name))
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
resource "test_instance" "foo1" {
|
||||
ami = "bar"
|
||||
|
||||
// shell has been configured to sleep for one second
|
||||
provisioner "shell" {}
|
||||
}
|
||||
|
||||
resource "test_instance" "foo2" {
|
||||
ami = "bar"
|
||||
|
||||
// shell has been configured to sleep for one second
|
||||
provisioner "shell" {}
|
||||
}
|
Loading…
Reference in New Issue