Skip to content

Commit 605a7b6

Browse files
committed
Remove WallClockAt
1 parent 9b7d814 commit 605a7b6

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

tester/tester.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ type testTimer struct {
4848
// At is the time this timer is scheduled for in test time
4949
At time.Time
5050

51-
// WallClockAt is the time this timer is scheduled for in wall-clock time
52-
WallClockAt time.Time
53-
5451
// Callback is called when the timer should fire.
5552
Callback *func()
5653

@@ -428,28 +425,21 @@ func (wt *workflowTester[TResult]) fireTimer() bool {
428425
{
429426
t := wt.timers[0]
430427

431-
wt.logger.Debug("Scheduling wall-clock timer", "at", t.WallClockAt)
432-
433-
// wt.nextTimer = t
428+
wt.logger.Debug("Scheduling wall-clock timer", "at", t.At)
434429

435-
if wt.wallClock.Now().After(t.WallClockAt) {
436-
// Fire timer
437-
wt.timers = wt.timers[1:]
438-
wt.callbacks <- t.fire
430+
// Determine when this should run
431+
remainingTime := t.At.Sub(wt.clock.Now())
439432

440-
return true
441-
} else if wt.wallClockTimer == nil {
442-
// Schedule timer
443-
wt.wallClockTimer = wt.wallClock.AfterFunc(t.WallClockAt.Sub(wt.wallClock.Now()), func() {
444-
wt.callbacks <- func() *history.WorkflowEvent {
445-
// Remove timer
446-
wt.timers = wt.timers[1:]
447-
wt.wallClockTimer = nil
433+
// Schedule timer
434+
wt.wallClockTimer = wt.wallClock.AfterFunc(remainingTime, func() {
435+
wt.callbacks <- func() *history.WorkflowEvent {
436+
// Remove timer
437+
wt.timers = wt.timers[1:]
438+
wt.wallClockTimer = nil
448439

449-
return t.fire()
450-
}
451-
})
452-
}
440+
return t.fire()
441+
}
442+
})
453443
}
454444
}
455445

@@ -633,7 +623,6 @@ func (wt *workflowTester[TResult]) scheduleTimer(instance *core.WorkflowInstance
633623
Instance: instance,
634624
ScheduleEventID: event.ScheduleEventID,
635625
At: e.At,
636-
WallClockAt: wt.wallClock.Now().Add(e.At.Sub(wt.clock.Now())),
637626
TimerEvent: &history.WorkflowEvent{
638627
WorkflowInstance: instance,
639628
HistoryEvent: event,

tester/tester_activity_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ func Test_LongActivity(t *testing.T) {
6060

6161
func Test_ActivityRaceWithSignal(t *testing.T) {
6262
activity1 := func() (string, error) {
63-
time.Sleep(200 * time.Millisecond)
64-
6563
return "activity", nil
6664
}
6765

@@ -92,7 +90,9 @@ func Test_ActivityRaceWithSignal(t *testing.T) {
9290

9391
tester := NewWorkflowTester[string](wf, WithTestTimeout(time.Second*3))
9492

95-
tester.OnActivity(activity1).Return("activity", nil)
93+
tester.OnActivity(activity1).Run(func(args mock.Arguments) {
94+
time.Sleep(200 * time.Millisecond)
95+
}).Return("activity", nil)
9696

9797
tester.ScheduleCallback(time.Millisecond*100, func() {
9898
tester.SignalWorkflow("signal", "stop")

0 commit comments

Comments
 (0)