Atlas › Test

TestTimerFire

Exact test identity: go.temporal.io/server/common/timer/TestRemoteTimerGateSuite/TestTimerFire

Package
go.temporal.io/server/common/timer
Suite / test hierarchy
TestRemoteTimerGateSuite/TestTimerFire
Test
TestTimerFire
Introduced at
TestTimerFire, TestTimerSetCurrentTime_Update_TimerFired Frontier kind: Test frontier
Covered ranges
14
Covered lines
42
Covered files
1

Co-introduced tests

1 other test enter at the same concept.

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/timer/remote_gate.go 42 covered LOC · 14 ranges

Open complete file

29
30 // NewRemoteGate create a new timer gate instance
31 > func NewRemoteGate() RemoteGate { remote_gate.go
32 > rg := &RemoteGateImpl{
33 > currentTime: time.Time{},
34 > nextWakeupTime: time.Time{},
35 > fireCh: make(chan struct{}, 1),
36 > }
37 > return rg
38 > }
39
40 // FireCh return the channel which will be fired when time is up
41 > func (rg *RemoteGateImpl) FireCh() <-chan struct{} { remote_gate.go
42 > return rg.fireCh
43 > }
44
45 // FireAfter check will the timer get fired after a certain time
54 // Update the timer gate, return true if update is a success.
55 // Success means timer is idle or timer is set with a sooner time to fire
56 > func (rg *RemoteGateImpl) Update(nextTime time.Time) bool { remote_gate.go
57 > rg.Lock()
58 > defer rg.Unlock()
59 >
60 > active := rg.currentTime.Before(rg.nextWakeupTime)
61 > if active {
62 if rg.nextWakeupTime.Before(nextTime) {
63 // current time < next wake up time < next time
78
79 // this means the timer, before stopped, has already fired / never active
80 > if !rg.currentTime.Before(nextTime) { remote_gate.go
81 // next time is <= current time, need to fire immediately
82 // whether to update next wake-up time or not is irrelevant
83 rg.fire()
84 > } else { remote_gate.go
85 > // next time > current time remote_gate.go
86 > rg.nextWakeupTime = nextTime
87 > }
88 > return true remote_gate.go
89 }
90
97 // if new "current" time is after the next wake-up time, return true if
98 // "current" is actually updated
99 > func (rg *RemoteGateImpl) SetCurrentTime(currentTime time.Time) bool { remote_gate.go
100 > rg.Lock()
101 > defer rg.Unlock()
102 >
103 > if !rg.currentTime.Before(currentTime) {
104 // new current time is <= current time
105 return false
107
108 // NOTE: do not update the current time now
109 > if !rg.currentTime.Before(rg.nextWakeupTime) { remote_gate.go
110 > // current time already >= next wakeup time remote_gate.go
111 > // avoid duplicate fire
112 > rg.currentTime = currentTime
113 > return true
114 > }
115
116 > rg.currentTime = currentTime remote_gate.go
117 > if !rg.currentTime.Before(rg.nextWakeupTime) {
118 > rg.fire() remote_gate.go
119 > }
120 > return true remote_gate.go
121 }
122
123 > func (rg *RemoteGateImpl) fire() { remote_gate.go
124 > select {
125 > case rg.fireCh <- struct{}{}:
126 // timer successfully triggered
127 default: