@@ -6,19 +6,21 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
6
6
describe . skipIf ( driverTestConfig . skip ?. schedule ) (
7
7
"Actor Schedule Tests" ,
8
8
( ) => {
9
+ // See alarm + actor sleeping test in actor-sleep.ts
10
+
9
11
describe ( "Scheduled Alarms" , ( ) => {
10
12
test ( "executes c.schedule.at() with specific timestamp" , async ( c ) => {
11
13
const { client } = await setupDriverTest ( c , driverTestConfig ) ;
12
14
13
15
// Create instance
14
16
const scheduled = client . scheduled . getOrCreate ( ) ;
15
17
16
- // Schedule a task to run in 100ms using timestamp
17
- const timestamp = Date . now ( ) + 100 ;
18
+ // Schedule a task to run using timestamp
19
+ const timestamp = Date . now ( ) + 250 ;
18
20
await scheduled . scheduleTaskAt ( timestamp ) ;
19
21
20
22
// Wait for longer than the scheduled time
21
- await waitFor ( driverTestConfig , 200 ) ;
23
+ await waitFor ( driverTestConfig , 500 ) ;
22
24
23
25
// Verify the scheduled task ran
24
26
const lastRun = await scheduled . getLastRun ( ) ;
@@ -34,11 +36,11 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
34
36
// Create instance
35
37
const scheduled = client . scheduled . getOrCreate ( ) ;
36
38
37
- // Schedule a task to run in 100ms using delay
38
- await scheduled . scheduleTaskAfter ( 100 ) ;
39
+ // Schedule a task to run using delay
40
+ await scheduled . scheduleTaskAfter ( 250 ) ;
39
41
40
42
// Wait for longer than the scheduled time
41
- await waitFor ( driverTestConfig , 200 ) ;
43
+ await waitFor ( driverTestConfig , 500 ) ;
42
44
43
45
// Verify the scheduled task ran
44
46
const lastRun = await scheduled . getLastRun ( ) ;
@@ -48,31 +50,6 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
48
50
expect ( scheduledCount ) . toBe ( 1 ) ;
49
51
} ) ;
50
52
51
- test ( "scheduled tasks persist across actor restarts" , async ( c ) => {
52
- const { client } = await setupDriverTest ( c , driverTestConfig ) ;
53
-
54
- // Create instance and schedule
55
- const scheduled = client . scheduled . getOrCreate ( ) ;
56
- await scheduled . scheduleTaskAfter ( 200 ) ;
57
-
58
- // Wait a little so the schedule is stored but hasn't triggered yet
59
- await waitFor ( driverTestConfig , 100 ) ;
60
-
61
- // Get a new reference to simulate actor restart
62
- const newInstance = client . scheduled . getOrCreate ( ) ;
63
-
64
- // Verify the schedule still exists but hasn't run yet
65
- const initialCount = await newInstance . getScheduledCount ( ) ;
66
- expect ( initialCount ) . toBe ( 0 ) ;
67
-
68
- // Wait for the scheduled task to execute
69
- await waitFor ( driverTestConfig , 200 ) ;
70
-
71
- // Verify the scheduled task ran after "restart"
72
- const scheduledCount = await newInstance . getScheduledCount ( ) ;
73
- expect ( scheduledCount ) . toBe ( 1 ) ;
74
- } ) ;
75
-
76
53
test ( "multiple scheduled tasks execute in order" , async ( c ) => {
77
54
const { client } = await setupDriverTest ( c , driverTestConfig ) ;
78
55
@@ -83,22 +60,22 @@ export function runActorScheduleTests(driverTestConfig: DriverTestConfig) {
83
60
await scheduled . clearHistory ( ) ;
84
61
85
62
// Schedule multiple tasks with different delays
86
- await scheduled . scheduleTaskAfterWithId ( "first" , 100 ) ;
87
- await scheduled . scheduleTaskAfterWithId ( "second" , 300 ) ;
88
- await scheduled . scheduleTaskAfterWithId ( "third" , 500 ) ;
63
+ await scheduled . scheduleTaskAfterWithId ( "first" , 250 ) ;
64
+ await scheduled . scheduleTaskAfterWithId ( "second" , 750 ) ;
65
+ await scheduled . scheduleTaskAfterWithId ( "third" , 1250 ) ;
89
66
90
67
// Wait for first task only
91
- await waitFor ( driverTestConfig , 200 ) ;
68
+ await waitFor ( driverTestConfig , 500 ) ;
92
69
const history1 = await scheduled . getTaskHistory ( ) ;
93
70
expect ( history1 ) . toEqual ( [ "first" ] ) ;
94
71
95
72
// Wait for second task
96
- await waitFor ( driverTestConfig , 200 ) ;
73
+ await waitFor ( driverTestConfig , 500 ) ;
97
74
const history2 = await scheduled . getTaskHistory ( ) ;
98
75
expect ( history2 ) . toEqual ( [ "first" , "second" ] ) ;
99
76
100
77
// Wait for third task
101
- await waitFor ( driverTestConfig , 200 ) ;
78
+ await waitFor ( driverTestConfig , 500 ) ;
102
79
const history3 = await scheduled . getTaskHistory ( ) ;
103
80
expect ( history3 ) . toEqual ( [ "first" , "second" , "third" ] ) ;
104
81
} ) ;
0 commit comments