add timeout test to remote-exec
Add a test to remote-exec to make sure the proper timeout is honored during apply. TODO: we need some test helpers for provisioners, so they can all be verified.
This commit is contained in:
parent
2954d9849a
commit
56acda00bc
|
@ -2,11 +2,15 @@ package remoteexec
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/terraform/communicator"
|
||||
"github.com/hashicorp/terraform/communicator/remote"
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"github.com/hashicorp/terraform/terraform"
|
||||
|
@ -206,6 +210,59 @@ func TestResourceProvider_CollectScripts_scriptsEmpty(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestProvisionerTimeout(t *testing.T) {
|
||||
o := new(terraform.MockUIOutput)
|
||||
c := new(communicator.MockCommunicator)
|
||||
|
||||
disconnected := make(chan struct{})
|
||||
c.DisconnectFunc = func() error {
|
||||
close(disconnected)
|
||||
return nil
|
||||
}
|
||||
|
||||
completed := make(chan struct{})
|
||||
c.CommandFunc = func(cmd *remote.Cmd) error {
|
||||
defer close(completed)
|
||||
cmd.Init()
|
||||
time.Sleep(2 * time.Second)
|
||||
cmd.SetExitStatus(0, nil)
|
||||
return nil
|
||||
}
|
||||
c.ConnTimeout = time.Second
|
||||
c.UploadScripts = map[string]string{"hello": "echo hello"}
|
||||
c.RemoteScriptPath = "hello"
|
||||
|
||||
p := Provisioner().(*schema.Provisioner)
|
||||
conf := map[string]interface{}{
|
||||
"inline": []interface{}{"echo hello"},
|
||||
}
|
||||
|
||||
scripts, err := collectScripts(schema.TestResourceDataRaw(
|
||||
t, p.Schema, conf))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
done := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
defer close(done)
|
||||
if err := runScripts(ctx, o, c, scripts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-disconnected:
|
||||
t.Fatal("communicator disconnected before command completed")
|
||||
case <-completed:
|
||||
}
|
||||
|
||||
<-done
|
||||
}
|
||||
|
||||
func testConfig(t *testing.T, c map[string]interface{}) *terraform.ResourceConfig {
|
||||
r, err := config.NewRawConfig(c)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue