Atlas › Test
TestTimerFireAfterUpdate_Active_Updated
Exact test identity: go.temporal.io/server/common/timer/TestRemoteTimerGateSuite/TestTimerFireAfterUpdate_Active_Updated
- Package
go.temporal.io/server/common/timer
- Suite / test hierarchy
TestRemoteTimerGateSuite/TestTimerFireAfterUpdate_Active_Updated
- Test
TestTimerFireAfterUpdate_Active_Updated
- Introduced at
- remote_gate.go ×1 Frontier kind: Joint frontier
- Covered ranges
- 17
- Covered lines
- 48
- Covered files
- 1
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/common/timer/remote_gate.go 48 covered LOC · 17 ranges
Open complete file
29
30
// NewRemoteGate create a new timer gate instance
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 {
63
// current time < next wake up time < next time
64
return false
65
}
66
69
>
rg.nextWakeupTime = nextTime
70
>
return true
71
>
}
72
73
// next time <= current time < next wake-up time
78
79
// this means the timer, before stopped, has already fired / never active
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()
86
>
rg.nextWakeupTime = nextTime
87
>
}
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
111
>
// avoid duplicate fire
112
>
rg.currentTime = currentTime
113
>
return true
114
>
}
115
117
>
if !rg.currentTime.Before(rg.nextWakeupTime) {
119
>
}
121
}
122
124
>
select {
125
>
case rg.fireCh <- struct{}{}:
126
// timer successfully triggered
127
default: