Skip to content

Commit 0c591fe

Browse files
committed
chore: add stabilization delay to client's startFlow
1 parent e36a7e3 commit 0c591fe

12 files changed

+149
-223
lines changed

pkgs/client/__tests__/integration/concurrent-operations.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ describe('Concurrent Operations Tests', () => {
4141
expect(run1.flow_slug).toBe(flow1.slug);
4242
expect(run2.flow_slug).toBe(flow2.slug);
4343

44-
// Give realtime subscriptions time to establish
45-
await new Promise(resolve => setTimeout(resolve, 300));
46-
4744
// Get and complete tasks from both flows
4845
console.log('=== Completing steps ===');
4946

@@ -203,9 +200,6 @@ describe('Concurrent Operations Tests', () => {
203200
const uniqueRunIds = [...new Set(runIds)];
204201
expect(uniqueRunIds.length).toBe(3);
205202

206-
// Give subscriptions time to establish
207-
await new Promise(resolve => setTimeout(resolve, 300));
208-
209203
// Poll for all tasks and complete them sequentially for reliability
210204
const allTasks = await readAndStart(sql, sqlClient, testFlow.slug, 5, 5);
211205
expect(allTasks.length).toBe(3); // One task per run
@@ -280,9 +274,6 @@ describe('Concurrent Operations Tests', () => {
280274
const runA = await pgflowClient.startFlow(flowA.slug, { type: 'flow-a' });
281275
const runB = await pgflowClient.startFlow(flowB.slug, { type: 'flow-b' });
282276

283-
// Give subscriptions time to establish
284-
await new Promise(resolve => setTimeout(resolve, 300));
285-
286277
// Get tasks from both flows
287278
const tasksA = await readAndStart(sql, sqlClient, flowA.slug, 2, 5);
288279
const tasksB = await readAndStart(sql, sqlClient, flowB.slug, 2, 5);

pkgs/client/__tests__/integration/full-stack-dsl.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ describe('Full Stack DSL Integration', () => {
8787
expect(run.flow_slug).toBe(SimpleFlow.slug);
8888
expect(run.input).toEqual(input);
8989

90-
// Give realtime subscription time to establish
91-
await new Promise((resolve) => setTimeout(resolve, 200));
92-
9390
// 7. Execute the complete flow lifecycle
9491
console.log('=== Step 1: Completing fetch step ===');
9592
let tasks = await readAndStart(sql, sqlClient, SimpleFlow.slug, 1, 5);

pkgs/client/__tests__/integration/happy-path-e2e.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ describe('Happy Path E2E Integration', () => {
6565
expect(run.status).toBe(FlowRunStatus.Started);
6666
expect(run.input).toEqual(input);
6767

68-
// Give realtime subscription time to establish
69-
await new Promise(resolve => setTimeout(resolve, 200));
70-
7168
// Step 1: Complete fetch step
7269
console.log('=== Step 1: Completing fetch step ===');
7370
let tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);

pkgs/client/__tests__/integration/input-validation.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ describe('Input Validation', () => {
215215
run.on('*', runTracker.callback);
216216
run.step('producer').on('*', stepTracker.callback);
217217

218-
// Give realtime subscription time to establish
219-
await new Promise(resolve => setTimeout(resolve, 100));
220-
221218
// Execute the producer step
222219
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
223220
expect(tasks).toHaveLength(1);
@@ -294,9 +291,6 @@ describe('Input Validation', () => {
294291

295292
const run = await pgflowClient.startFlow(testFlow.slug, { data: 'test' });
296293

297-
// Give realtime subscription time to establish
298-
await new Promise(resolve => setTimeout(resolve, 100));
299-
300294
// Execute the producer step
301295
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
302296
expect(tasks).toHaveLength(1);

pkgs/client/__tests__/integration/network-resilience.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ describe('Network Resilience Tests', () => {
4444
}
4545
});
4646

47-
// Give subscription time to establish
48-
await new Promise((resolve) => setTimeout(resolve, 200));
49-
5047
// Complete first step before disconnection
5148
let tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
5249
expect(tasks).toHaveLength(1);
@@ -151,9 +148,6 @@ describe('Network Resilience Tests', () => {
151148
});
152149
}
153150

154-
// Give subscription time to establish
155-
await new Promise((resolve) => setTimeout(resolve, 200));
156-
157151
// Complete step while monitoring connection
158152
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
159153
expect(tasks).toHaveLength(1);

pkgs/client/__tests__/integration/real-flow-execution.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ describe('Real Flow Execution', () => {
3535
expect(run.run_id).toBeDefined();
3636
expect(run.flow_slug).toBe(testFlow.slug);
3737

38-
// Give realtime subscription time to establish properly
39-
await new Promise((resolve) => setTimeout(resolve, 2000));
40-
4138
// Poll for task
4239
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
4340

@@ -111,9 +108,6 @@ describe('Real Flow Execution', () => {
111108
const step = run.step('event_step');
112109
step.on('*', stepTracker.callback);
113110

114-
// Give realtime subscription time to establish
115-
await new Promise((resolve) => setTimeout(resolve, 100));
116-
117111
// Poll and complete task
118112
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
119113
await sqlClient.completeTask(tasks[0], { hello: 'world' });
@@ -217,9 +211,6 @@ describe('Real Flow Execution', () => {
217211
const tracker = createEventTracker();
218212
dependentStep.on('*', tracker.callback);
219213

220-
// Give realtime subscription time to establish
221-
await new Promise((resolve) => setTimeout(resolve, 100));
222-
223214
// Complete root step - this will trigger dependent_step to start
224215
const rootTasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
225216
expect(rootTasks[0].step_slug).toBe('root_step');
@@ -401,9 +392,6 @@ describe('Real Flow Execution', () => {
401392
expect(step.status).toBe(FlowStepStatus.Started);
402393
expect(step.started_at).toBeDefined();
403394

404-
// Give realtime subscription time to establish
405-
await new Promise((resolve) => setTimeout(resolve, 100));
406-
407395
// waitForStatus should resolve immediately since step is already Started
408396
const waitPromise = step.waitForStatus(FlowStepStatus.Started, {
409397
timeoutMs: 5000,

pkgs/client/__tests__/integration/realtime-send.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ describe('Realtime Send Integration', () => {
3737
await subscriptionPromise;
3838
console.log('Channel fully subscribed and ready');
3939

40-
// Additional wait to ensure realtime connection is stable
41-
await new Promise((resolve) => setTimeout(resolve, 200));
42-
4340
// 4. Send event via SQL realtime.send() function
4441
const dbPayload = {
4542
test_message: 'Hello from SQL realtime.send()!',

pkgs/client/__tests__/integration/reconnection.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ describe('Reconnection Integration Tests', () => {
4343
reconnectionEvents.push(event.event_type);
4444
});
4545

46-
// Give realtime subscription time to establish
47-
await new Promise((resolve) => setTimeout(resolve, 200));
48-
4946
// Simulate network interruption by creating a new client
5047
// This forces the underlying channel to be recreated
5148
const newSupabaseClient = createTestSupabaseClient();
@@ -110,9 +107,6 @@ describe('Reconnection Integration Tests', () => {
110107
expect(run.status).toBe(FlowRunStatus.Started);
111108
expect(run.input).toEqual(input);
112109

113-
// Give initial subscription time to establish
114-
await new Promise((resolve) => setTimeout(resolve, 200));
115-
116110
// Simulate disconnection by disposing the client and creating a new one
117111
pgflowClient.dispose(run.run_id);
118112

@@ -174,9 +168,6 @@ describe('Reconnection Integration Tests', () => {
174168
const input = { data: 'rapid-test' };
175169
const originalRun = await pgflowClient.startFlow(testFlow.slug, input);
176170

177-
// Give initial subscription time to establish
178-
await new Promise((resolve) => setTimeout(resolve, 200));
179-
180171
// Create multiple run instances rapidly (simulates rapid reconnections)
181172
const runs = await Promise.all([
182173
pgflowClient.getRun(originalRun.run_id),

pkgs/client/__tests__/integration/regressions/step-failed-event-bug.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ describe('Step Failed Event Broadcasting', () => {
3838
step.on('*', stepTracker.callback);
3939
run.on('*', runTracker.callback);
4040

41-
// Give realtime subscription time to establish
42-
await new Promise(resolve => setTimeout(resolve, 100));
43-
4441
// Poll and start the task (uses pgmq.read_with_poll and pgflow.start_tasks internally)
4542
const tasks = await readAndStart(sql, sqlClient, testFlow.slug, 1, 5);
4643
expect(tasks).toHaveLength(1);

pkgs/client/__tests__/integration/wait-for-status-failure.test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ describe('waitForStatus - Failure Scenarios', () => {
3434
const stepTracker = createEventTracker();
3535
step.on('*', stepTracker.callback);
3636

37-
// Give realtime subscription time to establish
38-
await new Promise(resolve => setTimeout(resolve, 100));
39-
4037
// Start waiting for Failed status (before the step actually fails)
4138
const waitPromise = step.waitForStatus(FlowStepStatus.Failed, { timeoutMs: 10000 });
4239

@@ -90,9 +87,6 @@ describe('waitForStatus - Failure Scenarios', () => {
9087
const runTracker = createEventTracker();
9188
run.on('*', runTracker.callback);
9289

93-
// Give realtime subscription time to establish
94-
await new Promise(resolve => setTimeout(resolve, 100));
95-
9690
// Start waiting for Failed status (before the run actually fails)
9791
const waitPromise = run.waitForStatus(FlowRunStatus.Failed, { timeoutMs: 10000 });
9892

@@ -139,9 +133,6 @@ describe('waitForStatus - Failure Scenarios', () => {
139133
const run = await pgflowClient.startFlow(testFlow.slug, { test: 'timeout' });
140134
const step = run.step('normal_step');
141135

142-
// Give realtime subscription time to establish
143-
await new Promise(resolve => setTimeout(resolve, 100));
144-
145136
// Wait for Failed status with a short timeout (step will complete normally, not fail)
146137
const waitPromise = step.waitForStatus(FlowStepStatus.Failed, { timeoutMs: 2000 });
147138

@@ -186,9 +177,6 @@ describe('waitForStatus - Failure Scenarios', () => {
186177
run.on('*', runTracker.callback);
187178
step.on('*', stepTracker.callback);
188179

189-
// Give realtime subscription time to establish
190-
await new Promise(resolve => setTimeout(resolve, 100));
191-
192180
// Wait for both step and run to fail
193181
const stepWaitPromise = step.waitForStatus(FlowStepStatus.Failed, { timeoutMs: 10000 });
194182
const runWaitPromise = run.waitForStatus(FlowRunStatus.Failed, { timeoutMs: 10000 });

0 commit comments

Comments
 (0)