From c0dda6a7b34defb8e60f46a67bfc357ee846c1b4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 17 Feb 2017 13:29:13 -0500 Subject: [PATCH] test failure for windows local locks --- state/local_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/state/local_test.go b/state/local_test.go index 27d1763848..76abde1ce4 100644 --- a/state/local_test.go +++ b/state/local_test.go @@ -73,6 +73,30 @@ func TestLocalStateLocks(t *testing.T) { } } +// Verify that we can write to the state file, as Windows' mandatory locking +// will prevent writing to a handle different than the one that hold the lock. +func TestLocalState_writeWhileLocked(t *testing.T) { + s := testLocalState(t) + 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.WriteState(TestStateInitial()); err != nil { + t.Fatal(err) + } +} + func TestLocalState_pathOut(t *testing.T) { f, err := ioutil.TempFile("", "tf") if err != nil {