Skip to content

Commit d0b21c4

Browse files
committed
test: expand realtime event tests for complete, fail, and run completion scenarios
- Updated SQL tests to increase plan counts and verify additional event behaviors - Added checks to ensure no step:failed or run:completed events are sent in certain cases - Improved validation of completed_at timestamps and payload contents across multiple tests - Enhanced test coverage for realtime messaging logic in task completion, failure, and run finalization
1 parent f494db9 commit d0b21c4

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

pkgs/core/supabase/tests/realtime/complete_task_events.test.sql

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
begin;
2-
select plan(7);
2+
select plan(9);
33

44
-- Ensure partition exists for realtime.messages
55
select pgflow_tests.create_realtime_partition();
@@ -48,14 +48,14 @@ select is(
4848

4949
-- Test 4: Verify completed_at timestamp exists and is valid
5050
select ok(
51-
(select (payload->>'completed_at')::timestamptz is not null
51+
(select (payload->>'completed_at')::timestamptz is not null
5252
from pgflow_tests.get_realtime_message('step:completed', (select run_id from run_ids), 'first')),
5353
'The step:completed event should include a completed_at timestamp'
5454
);
5555

5656
-- Test 5: Verify output data is included in payload
5757
select is(
58-
(select payload->'output'->>'result'
58+
(select payload->'output'->>'result'
5959
from pgflow_tests.get_realtime_message('step:completed', (select run_id from run_ids), 'first')),
6060
'success',
6161
'The step:completed event should contain the correct output data'
@@ -75,6 +75,20 @@ select is(
7575
'The step:completed event should have the correct topic (pgflow:run:<run_id>)'
7676
);
7777

78+
-- Test 8: Verify no step:failed events were sent for the completed step
79+
select is(
80+
pgflow_tests.count_realtime_events('step:failed', (select run_id from run_ids), 'first'),
81+
0::int,
82+
'pgflow.complete_task should NOT send any step:failed events'
83+
);
84+
85+
-- Test 9: Verify no run:completed event was sent (since there are more steps to complete)
86+
select is(
87+
pgflow_tests.count_realtime_events('run:completed', (select run_id from run_ids)),
88+
0::int,
89+
'pgflow.complete_task should NOT send run:completed event when steps remain incomplete'
90+
);
91+
7892
-- Clean up
7993
drop table if exists run_ids;
8094
drop table if exists completed_tasks;

pkgs/core/supabase/tests/realtime/fail_task_events.test.sql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
begin;
2-
select plan(3);
2+
select plan(5);
33

44
-- Ensure partition exists for realtime.messages
55
select pgflow_tests.create_realtime_partition();
@@ -47,6 +47,20 @@ select is(
4747
'The run:failed event should have the correct topic (pgflow:run:<run_id>)'
4848
);
4949

50+
-- Test 4: Verify no step:completed events were sent for the failed step
51+
select is(
52+
pgflow_tests.count_realtime_events('step:completed', (select run_id from run_ids), 'first'),
53+
0::int,
54+
'pgflow.fail_task should NOT send any step:completed events for the failed step'
55+
);
56+
57+
-- Test 5: Verify no run:completed events were sent
58+
select is(
59+
pgflow_tests.count_realtime_events('run:completed', (select run_id from run_ids)),
60+
0::int,
61+
'pgflow.fail_task should NOT send any run:completed events when a run fails'
62+
);
63+
5064
-- Clean up
5165
drop table if exists run_ids;
5266
drop table if exists failed_tasks;

pkgs/core/supabase/tests/realtime/maybe_complete_run_events.test.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
begin;
2-
select plan(5);
2+
select plan(6);
33

44
-- Ensure partition exists for realtime.messages
55
select pgflow_tests.create_realtime_partition();
@@ -50,7 +50,7 @@ select is(
5050

5151
-- Test 4: Verify completed_at timestamp exists and is valid
5252
select ok(
53-
(select (payload->>'completed_at')::timestamptz is not null
53+
(select (payload->>'completed_at')::timestamptz is not null
5454
from pgflow_tests.get_realtime_message('run:completed', (select run_id from run_ids))),
5555
'The run:completed event should include a completed_at timestamp'
5656
);
@@ -62,6 +62,13 @@ select is(
6262
'The run:completed event should have the correct topic (pgflow:run:<run_id>)'
6363
);
6464

65+
-- Test 6: Verify no run:failed events were sent
66+
select is(
67+
pgflow_tests.count_realtime_events('run:failed', (select run_id from run_ids)),
68+
0::int,
69+
'pgflow.maybe_complete_run should NOT send any run:failed events on successful completion'
70+
);
71+
6572
-- Clean up
6673
drop table if exists run_ids;
6774
drop table if exists completed_tasks;

0 commit comments

Comments
 (0)