Skip to content

Commit

Permalink
Adding more test to local timer gate (cadence-workflow#1064)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxing1292 authored Aug 22, 2018
1 parent f58d37c commit 8f7aadb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions service/history/timerGate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,37 @@ func (s *localTimerGateSuite) TestTimerWillFire_Zero() {
// this test is to validate initial notification will trigger a scan of timer
s.localTimerGate.Update(time.Time{})
s.False(s.localTimerGate.FireAfter(time.Now()))

select { // this is to drain existing signal
case <-s.localTimerGate.FireChan():
case <-time.NewTimer(time.Second).C:
}

now := time.Now()
newTimer := now.Add(1 * time.Second)
deadline := now.Add(2 * time.Second)
s.localTimerGate.Update(newTimer)
select {
case <-s.localTimerGate.FireChan():
case <-time.NewTimer(deadline.Sub(now)).C:
s.Fail("timer should fire")
}
s.localTimerGate.Update(time.Time{})
select { // this is to drain existing signal
case <-s.localTimerGate.FireChan():
case <-time.NewTimer(time.Second).C:
s.Fail("timer should fire")
}

now = time.Now()
newTimer = now.Add(1 * time.Second)
s.localTimerGate.Update(newTimer)
s.localTimerGate.Update(time.Time{})
select { // this is to drain existing signal
case <-s.localTimerGate.FireChan():
case <-time.NewTimer(time.Second).C:
s.Fail("timer should fire")
}
}

func (s *localTimerGateSuite) TestTimerWillFire() {
Expand Down

0 comments on commit 8f7aadb

Please sign in to comment.