helper/shadow: keyedValue.WaitForChange must unlock

This commit is contained in:
Mitchell Hashimoto 2016-10-21 17:57:00 -07:00
parent f8e35ecb2f
commit de827887bf
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
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 w.closed {
w.lock.Unlock()
return ErrClosed
}

View File

@ -312,3 +312,25 @@ func TestKeyedValueWaitForChange_closed(t *testing.T) {
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)
}
}