@@ -20,6 +20,10 @@ static constexpr kj::Date twoMs = 2 * kj::MILLISECONDS + kj::UNIX_EPOCH;
2020static constexpr kj::Date threeMs = 3 * kj::MILLISECONDS + kj::UNIX_EPOCH;
2121static constexpr kj::Date fourMs = 4 * kj::MILLISECONDS + kj::UNIX_EPOCH;
2222static constexpr kj::Date fiveMs = 5 * kj::MILLISECONDS + kj::UNIX_EPOCH;
23+ // Used as the "current time" parameter for armAlarmHandler in tests.
24+ // Set to epoch (before all test alarm times) so existing tests aren't affected by
25+ // the overdue alarm check.
26+ static constexpr kj::Date testCurrentTime = kj::UNIX_EPOCH;
2327
2428template <typename T>
2529kj::Promise<T> eagerlyReportExceptions (kj::Promise<T> promise, kj::SourceLocation location = {}) {
@@ -586,7 +590,7 @@ KJ_TEST("tells alarm handler to cancel when committed alarm is empty") {
586590 ActorSqliteTest test;
587591
588592 {
589- auto armResult = test.actor .armAlarmHandler (oneMs, false );
593+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
590594 // We expect armAlarmHandler() to tell us to cancel the alarm.
591595 KJ_ASSERT (armResult.is <ActorCache::CancelAlarmHandler>());
592596 auto waitPromise = kj::mv (armResult.get <ActorCache::CancelAlarmHandler>().waitBeforeCancel );
@@ -612,7 +616,7 @@ KJ_TEST("tells alarm handler to reschedule when handler alarm is later than comm
612616 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
613617
614618 // Request handler run at 2ms. Expect cancellation with rescheduling.
615- auto armResult = test.actor .armAlarmHandler (twoMs, false );
619+ auto armResult = test.actor .armAlarmHandler (twoMs, testCurrentTime, false );
616620 KJ_ASSERT (armResult.is <ActorSqlite::CancelAlarmHandler>());
617621 auto cancelResult = kj::mv (armResult.get <ActorSqlite::CancelAlarmHandler>());
618622
@@ -636,7 +640,7 @@ KJ_TEST("tells alarm handler to reschedule when handler alarm is earlier than co
636640 KJ_ASSERT (expectSync (test.getAlarm ()) == twoMs);
637641
638642 // Expect that armAlarmHandler() tells caller to cancel after rescheduling completes.
639- auto armResult = test.actor .armAlarmHandler (oneMs, false );
643+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
640644 KJ_ASSERT (armResult.is <ActorSqlite::CancelAlarmHandler>());
641645 auto cancelResult = kj::mv (armResult.get <ActorSqlite::CancelAlarmHandler>());
642646
@@ -661,7 +665,7 @@ KJ_TEST("does not cancel handler when local db alarm state is later than schedul
661665
662666 test.setAlarm (twoMs);
663667 {
664- auto armResult = test.actor .armAlarmHandler (oneMs, false );
668+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
665669 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
666670 }
667671 test.pollAndExpectCalls ({" commit" })[0 ]->fulfill ();
@@ -680,7 +684,7 @@ KJ_TEST("does not cancel handler when local db alarm state is earlier than sched
680684
681685 test.setAlarm (oneMs);
682686 {
683- auto armResult = test.actor .armAlarmHandler (twoMs, false );
687+ auto armResult = test.actor .armAlarmHandler (twoMs, testCurrentTime, false );
684688 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
685689 }
686690 test.pollAndExpectCalls ({" scheduleRun(1ms)" })[0 ]->fulfill ();
@@ -698,7 +702,7 @@ KJ_TEST("getAlarm() returns null during handler") {
698702 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
699703
700704 {
701- auto armResult = test.actor .armAlarmHandler (oneMs, false );
705+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
702706 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
703707 test.pollAndExpectCalls ({});
704708
@@ -719,7 +723,7 @@ KJ_TEST("alarm handler handle clears alarm when dropped with no writes") {
719723 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
720724
721725 {
722- auto armResult = test.actor .armAlarmHandler (oneMs, false );
726+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
723727 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
724728 }
725729 test.pollAndExpectCalls ({" commit" })[0 ]->fulfill ();
@@ -738,7 +742,7 @@ KJ_TEST("alarm deleter does not clear alarm when dropped with writes") {
738742 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
739743
740744 {
741- auto armResult = test.actor .armAlarmHandler (oneMs, false );
745+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
742746 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
743747 test.setAlarm (twoMs);
744748 }
@@ -759,7 +763,7 @@ KJ_TEST("can cancel deferred alarm deletion during handler") {
759763 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
760764
761765 {
762- auto armResult = test.actor .armAlarmHandler (oneMs, false );
766+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
763767 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
764768 test.actor .cancelDeferredAlarmDeletion ();
765769 }
@@ -778,7 +782,7 @@ KJ_TEST("canceling deferred alarm deletion outside handler has no effect") {
778782 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
779783
780784 {
781- auto armResult = test.actor .armAlarmHandler (oneMs, false );
785+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
782786 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
783787 }
784788 test.pollAndExpectCalls ({" commit" })[0 ]->fulfill ();
@@ -803,7 +807,7 @@ KJ_TEST("canceling deferred alarm deletion outside handler edge case") {
803807 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
804808
805809 {
806- auto armResult = test.actor .armAlarmHandler (oneMs, false );
810+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
807811 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
808812 }
809813 test.actor .cancelDeferredAlarmDeletion ();
@@ -825,7 +829,7 @@ KJ_TEST("canceling deferred alarm deletion is idempotent") {
825829 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
826830
827831 {
828- auto armResult = test.actor .armAlarmHandler (oneMs, false );
832+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
829833 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
830834 test.actor .cancelDeferredAlarmDeletion ();
831835 test.actor .cancelDeferredAlarmDeletion ();
@@ -846,7 +850,7 @@ KJ_TEST("alarm handler cleanup succeeds when output gate is broken") {
846850 test.pollAndExpectCalls ({});
847851 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
848852
849- auto armResult = test.actor .armAlarmHandler (oneMs, false );
853+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
850854 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
851855 auto deferredDelete = kj::mv (armResult.get <ActorSqlite::RunAlarmHandler>().deferredDelete );
852856
@@ -893,7 +897,7 @@ KJ_TEST("handler alarm is not deleted when commit fails") {
893897 KJ_ASSERT (expectSync (test.getAlarm ()) == oneMs);
894898
895899 {
896- auto armResult = test.actor .armAlarmHandler (oneMs, false );
900+ auto armResult = test.actor .armAlarmHandler (oneMs, testCurrentTime, false );
897901 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
898902
899903 KJ_ASSERT (expectSync (test.getAlarm ()) == kj::none);
@@ -1340,7 +1344,7 @@ KJ_TEST("rolling back transaction leaves deferred alarm deletion in expected sta
13401344 KJ_ASSERT (expectSync (test.getAlarm ()) == twoMs);
13411345
13421346 {
1343- auto armResult = test.actor .armAlarmHandler (twoMs, false );
1347+ auto armResult = test.actor .armAlarmHandler (twoMs, testCurrentTime, false );
13441348 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
13451349
13461350 auto txn = test.actor .startTransaction ();
@@ -1373,7 +1377,7 @@ KJ_TEST("committing transaction leaves deferred alarm deletion in expected state
13731377 KJ_ASSERT (expectSync (test.getAlarm ()) == twoMs);
13741378
13751379 {
1376- auto armResult = test.actor .armAlarmHandler (twoMs, false );
1380+ auto armResult = test.actor .armAlarmHandler (twoMs, testCurrentTime, false );
13771381 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
13781382
13791383 auto txn = test.actor .startTransaction ();
@@ -1404,7 +1408,7 @@ KJ_TEST("rolling back nested transaction leaves deferred alarm deletion in expec
14041408 KJ_ASSERT (expectSync (test.getAlarm ()) == twoMs);
14051409
14061410 {
1407- auto armResult = test.actor .armAlarmHandler (twoMs, false );
1411+ auto armResult = test.actor .armAlarmHandler (twoMs, testCurrentTime, false );
14081412 KJ_ASSERT (armResult.is <ActorSqlite::RunAlarmHandler>());
14091413
14101414 auto txn1 = test.actor .startTransaction ();
0 commit comments