panic when unbalanced localState.Resume() is detected

This commit is contained in:
Wojciech Bederski 2015-09-17 11:32:08 +02:00
parent 4cd1b09ad7
commit 9a1b52171f
2 changed files with 13 additions and 1 deletions

View File

@ -114,7 +114,10 @@ func (l *localState) Pause() {
// Resume is used to resume state synchronization
func (l *localState) Resume() {
atomic.AddInt32(&l.paused, -1)
paused := atomic.AddInt32(&l.paused, -1)
if paused < 0 {
panic("unbalanced localState.Resume() detected")
}
l.changeMade()
}

View File

@ -685,6 +685,15 @@ func TestAgent_nestedPauseResume(t *testing.T) {
if l.isPaused() != false {
t.Fatal("localState should NOT be Paused after SECOND call to Resume()")
}
defer func() {
err := recover()
if err == nil {
t.Fatal("unbalanced Resume() should cause a panic()")
}
}()
l.Resume()
}
var testRegisterRules = `