test(scheduler): add unit tests for Healthy, LastTickAt, ComputeNextRun, panic recovery - #111
Closed
HongmingWang-Rabbit wants to merge 1 commit into
Closed
test(scheduler): add unit tests for Healthy, LastTickAt, ComputeNextRun, panic recovery#111HongmingWang-Rabbit wants to merge 1 commit into
HongmingWang-Rabbit wants to merge 1 commit into
Conversation
…un, panic recovery Added scheduler_test.go with 8 test cases covering all previously untested security-critical code paths from PR #90: TestLastTickAt_zero — zero time before first tick TestHealthy_beforeStart — false on fresh scheduler (zero lastTickAt) TestHealthy_freshTick — true when lastTickAt == now TestHealthy_stale — false when lastTickAt is 3×pollInterval ago TestComputeNextRun_valid — "0 * * * *" / UTC returns top-of-hour future time TestComputeNextRun_invalid — unparseable expression returns non-nil error TestComputeNextRun_invalidTimezone — unrecognised IANA zone returns non-nil error TestPanicRecovery — panicProxy crashes ProxyA2ARequest; scheduler goroutine recovers and remains Healthy To support these tests, scheduler.go gained four changes (minimal surface): 1. Added mu sync.RWMutex, lastTickAt time.Time, and tickInterval time.Duration fields to Scheduler. tickInterval defaults to pollInterval so production behaviour is unchanged; tests can override it directly. 2. Added LastTickAt() and Healthy() methods with read-lock protection. 3. tick() now records lastTickAt after wg.Wait() — a single atomic write under the mutex, no hot-path cost. 4. fireSchedule() got a deferred recover() so a panicking A2A proxy cannot crash the goroutine pool. Without this, TestPanicRecovery itself crashes the test binary — the test passing proves recovery is in place. Bug fix: ComputeNextRun previously silently fell back to UTC on an invalid timezone; it now returns a non-nil error. The schedules handler already validates the timezone before calling ComputeNextRun so this is a no-op for callers, but it makes the contract explicit and testable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4 tasks
Contributor
Author
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
platform/internal/scheduler/scheduler_test.go— the only previously untested security-critical package from PR #90.scheduler.gorequired to make the code testable (all additive, no behaviour change for existing callers)ComputeNextRunnow returns an error on invalid timezone instead of silently falling back to UTCTests added
TestLastTickAt_zeroLastTickAt()returns zerotime.Timebefore the first tickTestHealthy_beforeStartHealthy()is false on a fresh scheduler (zerolastTickAt)TestHealthy_freshTickHealthy()is true whenlastTickAt == nowTestHealthy_staleHealthy()is false whenlastTickAtis 3×pollIntervalago (beyond 2× threshold)TestComputeNextRun_valid"0 * * * *"/ UTC returns a future top-of-hour time, no errorTestComputeNextRun_invalidTestComputeNextRun_invalidTimezoneTestPanicRecoverypanicProxypanics insideProxyA2ARequest; scheduler goroutine recovers andHealthy()remains true — an unrecovered panic would crash the test binary, so the test completing is proofProduction changes to
scheduler.gomu,lastTickAt,tickIntervalfieldsLastTickAt(),Healthy(), and test-speed controlLastTickAt()/Healthy()methodstick()recordslastTickAtafterwg.Wait()fireSchedule()deferredrecover()ComputeNextRunreturns error on bad timezoneTest output
Full suite: all packages pass, zero failures.
Test plan
go test ./internal/scheduler/... -v— 8/8 passgo test ./...— full suite passes, no regressions🤖 Generated with Claude Code