Skip to content

Commit

Permalink
Improve scheduler workflow unit test (#4962)
Browse files Browse the repository at this point in the history
**What changed?**
The end of each test is signaled by time instead of iteration count,
which was really confusing.

**Why?**
Easier to write and maintain tests.
They now stop at exactly the right time and avoid spurious calls that
would trigger panics.

**How did you test it?**
is tests
  • Loading branch information
dnr authored and rodrigozhou committed Oct 31, 2023
1 parent 53a4979 commit cba2ce7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 41 deletions.
12 changes: 10 additions & 2 deletions service/worker/scheduler/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ const (
rateLimitedErrorType = "RateLimited"

nextTimeCacheV1Size = 10

impossibleHistorySize = 1e6 // just for testing, no real history can be this long
)

type (
Expand Down Expand Up @@ -249,7 +251,14 @@ func (s *scheduler) run() error {
s.pendingPatch = s.InitialPatch
s.InitialPatch = nil

for iters := s.tweakables.IterationsBeforeContinueAsNew; iters > 0 || s.pendingUpdate != nil || s.pendingPatch != nil; iters-- {
iters := s.tweakables.IterationsBeforeContinueAsNew
for {
// TODO: use the real GetContinueAsNewSuggested
continueAsNewSuggested := iters <= 0 || workflow.GetInfo(s.ctx).GetCurrentHistoryLength() >= impossibleHistorySize
if continueAsNewSuggested && s.pendingUpdate == nil && s.pendingPatch == nil {
break
}
iters--

t1 := timestamp.TimeValue(s.State.LastProcessedTime)
t2 := s.now()
Expand Down Expand Up @@ -288,7 +297,6 @@ func (s *scheduler) run() error {
// 3. a workflow that we were watching finished
s.sleep(nextWakeup)
s.updateTweakables()

}

// Any watcher activities will get cancelled automatically if running.
Expand Down
Loading

0 comments on commit cba2ce7

Please # to comment.