Merge pull request #9525 from hashicorp/b-shadow-block

helper/shadow: keyedValue.WaitForChange must unlock
This commit is contained in:
Mitchell Hashimoto 2016-10-22 11:56:14 -07:00 committed by GitHub
commit ab36666653
2 changed files with 23 additions and 0 deletions

View File

@ -58,6 +58,7 @@ func (w *KeyedValue) WaitForChange(k string) interface{} {
// If we're closed, we're closed // If we're closed, we're closed
if w.closed { if w.closed {
w.lock.Unlock()
return ErrClosed return ErrClosed
} }

View File

@ -312,3 +312,25 @@ func TestKeyedValueWaitForChange_closed(t *testing.T) {
t.Fatalf("bad: %#v", val) t.Fatalf("bad: %#v", val)
} }
} }
func TestKeyedValueWaitForChange_closedFirst(t *testing.T) {
var v KeyedValue
// Close
v.Close()
// Verify
val := v.WaitForChange("foo")
if val != ErrClosed {
t.Fatalf("bad: %#v", val)
}
// Set a value
v.SetValue("foo", 42)
// Try again
val = v.WaitForChange("foo")
if val != ErrClosed {
t.Fatalf("bad: %#v", val)
}
}