-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): extract helper functions for worker and sequence tes…
…ting Move common test utility functions to a shared _helpers.ts file to improve code reusability and reduce duplication in e2e tests
- Loading branch information
Showing
2 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { sql } from '../sql.ts'; | ||
import { delay } from 'jsr:@std/async'; | ||
|
||
export async function seqLastValue(): Promise<number> { | ||
const seqResult = await sql`SELECT last_value::integer FROM test_seq`; | ||
return seqResult[0].last_value; | ||
} | ||
|
||
export async function waitForSeqValue( | ||
value: number, | ||
message: string = 'Polling...' | ||
): Promise<number> { | ||
let lastVal = 0; | ||
while (lastVal < value) { | ||
console.log(`${message} current value:`, lastVal); | ||
await delay(1000); | ||
lastVal = await seqLastValue(); | ||
} | ||
return lastVal; | ||
} | ||
|
||
export async function fetchWorkers(workerName: string) { | ||
return await sql`SELECT * FROM supaworker.workers`; | ||
} | ||
|
||
export async function startWorker(workerName: string, seconds: number = 5) { | ||
await sql`SELECT supaworker.spawn(${workerName})`; | ||
|
||
let workers = await fetchWorkers(workerName); | ||
console.log('Waiting for worker to spawn...'); | ||
|
||
while (workers.length === 0) { | ||
await delay(500); | ||
workers = await fetchWorkers(workerName); | ||
} | ||
console.log('Worker spawned!'); | ||
} |
This file contains 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