add failing test for windows state locks

Refreshing a locked state on windows could return nil if the read path
was locked, no state was yet written, and the read path is the same as
the write path.

Add a test that locks then refreshes a newly initialized state struct.
This commit is contained in:
James Bardin 2018-03-19 17:09:53 -04:00
parent 60bc16305a
commit e10a7917e6
1 changed files with 39 additions and 0 deletions

View File

@ -166,3 +166,42 @@ func testLocalState(t *testing.T) *LocalState {
return ls
}
// Make sure we can refresh while the state is locked
func TestLocalState_refreshWhileLocked(t *testing.T) {
f, err := ioutil.TempFile("", "tf")
if err != nil {
t.Fatalf("err: %s", err)
}
err = terraform.WriteState(TestStateInitial(), f)
f.Close()
if err != nil {
t.Fatalf("err: %s", err)
}
s := &LocalState{Path: f.Name()}
defer os.Remove(s.Path)
// lock first
info := NewLockInfo()
info.Operation = "test"
lockID, err := s.Lock(info)
if err != nil {
t.Fatal(err)
}
defer func() {
if err := s.Unlock(lockID); err != nil {
t.Fatal(err)
}
}()
if err := s.RefreshState(); err != nil {
t.Fatal(err)
}
readState := s.State()
if readState == nil || readState.Lineage == "" {
t.Fatal("missing state")
}
}