Atlas › Test

TestTimeSkippingTimeSource_Now_NilGetter

Exact test identity: go.temporal.io/server/common/clock/TestTimeSkippingTimeSource_Now_NilGetter

Package
go.temporal.io/server/common/clock
Suite / test hierarchy
TestTimeSkippingTimeSource_Now_NilGetter
Test
TestTimeSkippingTimeSource_Now_NilGetter
Introduced at
time_skipping_time_source.go ×2 Frontier kind: Joint frontier
Covered ranges
8
Covered lines
30
Covered files
2

Covered source

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

go.temporal.io/server/common/clock/event_time_source.go 23 covered LOC · 5 ranges

Open complete file

39
40 // NewEventTimeSource returns a EventTimeSource with the current time set to Unix zero: 1970-01-01 00:00:00 +0000 UTC.
41 > func NewEventTimeSource() *EventTimeSource { event_time_source.go
42 > return &EventTimeSource{
43 > now: time.Unix(0, 0),
44 > }
45 > }
46
47 // Some clients depend on the fact that the runtime's timers do _not_ run synchronously.
55
56 // Now return the current time.
57 > func (ts *EventTimeSource) Now() time.Time { event_time_source.go
58 > ts.mu.RLock()
59 > defer ts.mu.RUnlock()
60 >
61 > return ts.now
62 > }
63
64 func (ts *EventTimeSource) Since(t time.Time) time.Duration {
106 // Update the fake current time. It returns the timeSource so that you can chain calls like this:
107 // timeSource := NewEventTimeSource().Update(time.Now())
108 > func (ts *EventTimeSource) Update(now time.Time) *EventTimeSource { event_time_source.go
109 > ts.mu.Lock()
110 > defer ts.mu.Unlock()
111 >
112 > ts.now = now
113 > ts.fireTimers()
114 > return ts
115 > }
116
117 // Advance the timer by the specified duration.
156
157 // fireTimers fires all timers that are ready.
158 > func (ts *EventTimeSource) fireTimers() { event_time_source.go
159 > n := 0
160 > for _, t := range ts.timers {
161 if t.deadline.After(ts.now) {
162 ts.timers[n] = t
go.temporal.io/server/common/clock/time_skipping_time_source.go 7 covered LOC · 3 ranges

Open complete file

20 // the base's Now()/Since() on every call. If getOffset is nil, the wrapper behaves
21 // as a pass-through to base.
22 > func WrapTimeSourceWithTimeSkipping(base TimeSource, getOffset func() time.Duration) TimeSource { time_skipping_time_source.go
23 > return &TimeSkippingTimeSourceWrapper{base: base, getOffset: getOffset}
24 > }
25
26 > func (ts *TimeSkippingTimeSourceWrapper) Now() time.Time { time_skipping_time_source.go
27 > t := ts.base.Now()
28 > if ts.getOffset != nil {
29 t = t.Add(ts.getOffset())
30 }
32 }
33