From 3d604851c27caf01c3f70728aaa2cf6061cae1e7 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 3 Apr 2017 11:33:38 -0400 Subject: [PATCH] test -lock-timeout from cli --- command/apply_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/command/apply_test.go b/command/apply_test.go index 661d88c76c..abc33dae57 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io/ioutil" + "log" "net" "net/http" "net/url" @@ -92,6 +93,42 @@ func TestApply_lockedState(t *testing.T) { } } +// test apply with locked state, waiting for unlock +func TestApply_lockedStateWait(t *testing.T) { + statePath := testTempFile(t) + + unlock, err := testLockState("./testdata", statePath) + if err != nil { + t.Fatal(err) + } + + // unlock during apply + go func() { + time.Sleep(500 * time.Millisecond) + unlock() + }() + + p := testProvider() + ui := new(cli.MockUi) + c := &ApplyCommand{ + Meta: Meta{ + ContextOpts: testCtxConfig(p), + Ui: ui, + }, + } + + // wait 4s just in case the lock process doesn't release in under a second, + // and we want our context to be alive for a second retry at the 3s mark. + args := []string{ + "-state", statePath, + "-lock-timeout", "4s", + testFixturePath("apply"), + } + if code := c.Run(args); code != 0 { + log.Fatalf("lock should have succeed in less than 3s: %s", ui.ErrorWriter) + } +} + // high water mark counter type hwm struct { sync.Mutex