Skip to content

Commit 62b04de

Browse files
reduce number of iframes for CI
1 parent aedc855 commit 62b04de

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

packages/web/tests/multiple_tabs_iframe.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ createMultipleTabsTest(WASQLiteVFS.OPFSCoopSyncVFS);
2323
async function createIframeWithPowerSyncClient(
2424
dbFilename: string,
2525
identifier: string,
26-
vfs?: WASQLiteVFS
26+
vfs?: WASQLiteVFS,
27+
waitForConnection?: boolean
2728
): Promise<IframeClient> {
2829
const iframe = document.createElement('iframe');
2930
// Make iframe visible for debugging
@@ -81,7 +82,7 @@ async function createIframeWithPowerSyncClient(
8182
</div>
8283
<script type="module">
8384
import { setupPowerSyncInIframe } from '${modulePath}';
84-
setupPowerSyncInIframe('${dbFilename}', '${identifier}', ${vfs ? `'${vfs}'` : 'undefined'});
85+
setupPowerSyncInIframe('${dbFilename}', '${identifier}', ${vfs ? `'${vfs}'` : 'undefined'}, ${waitForConnection ? 'true' : 'false'});
8586
</script>
8687
</body>
8788
</html>`;
@@ -251,7 +252,7 @@ function createMultipleTabsTest(vfs?: WASQLiteVFS) {
251252
const dbFilename = `test-multi-tab-${uuid()}.db`;
252253

253254
// Configurable number of tabs to create (excluding the long-lived tab)
254-
const NUM_TABS = 50;
255+
const NUM_TABS = 20;
255256

256257
it('should handle simultaneous close and reopen of tabs', async () => {
257258
// Step 1: Open a long-lived reference tab that stays open throughout the test
@@ -379,15 +380,10 @@ function createMultipleTabsTest(vfs?: WASQLiteVFS) {
379380
expect(queryResult.length).toBe(1);
380381
expect((queryResult[0] as { value: number }).value).toBe(1);
381382

382-
/**
383-
* Wait a little for the state to settle.
384-
*/
385-
await new Promise((resolve) => setTimeout(resolve, 1000));
386-
387383
// Step 6: Create a new tab which should trigger a connect. The shared sync worker should reconnect.
388384
// This ensures the shared sync worker is not stuck and is properly handling new connections
389385
const newTabIdentifier = `new-tab-${Date.now()}`;
390-
const newTab = await createIframeWithPowerSyncClient(dbFilename, newTabIdentifier, vfs);
386+
const newTab = await createIframeWithPowerSyncClient(dbFilename, newTabIdentifier, vfs, true);
391387
onTestFinished(async () => {
392388
try {
393389
await newTab.cleanup();

packages/web/tests/utils/iframeInitializer.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { PowerSyncDatabase, WASQLiteOpenFactory, WASQLiteVFS } from '@powersync/
77
*
88
* @param vfs - VFS option as a string (e.g., 'OPFSCoopSyncVFS' or 'IDBBatchAtomicVFS')
99
*/
10-
export async function setupPowerSyncInIframe(dbFilename: string, identifier: string, vfs?: string): Promise<void> {
10+
export async function setupPowerSyncInIframe(
11+
dbFilename: string,
12+
identifier: string,
13+
vfs?: string,
14+
waitForConnection?: boolean
15+
): Promise<void> {
1116
try {
1217
// Track the number of times fetchCredentials has been called
1318
let credentialsFetchCount = 0;
@@ -50,7 +55,11 @@ export async function setupPowerSyncInIframe(dbFilename: string, identifier: str
5055
});
5156

5257
// Connect to PowerSync (don't await this since we want to create multiple tabs)
53-
db.connect(connector, { connectionMethod: SyncStreamConnectionMethod.HTTP });
58+
const connectionPromise = db.connect(connector, { connectionMethod: SyncStreamConnectionMethod.HTTP });
59+
60+
if (waitForConnection) {
61+
await connectionPromise;
62+
}
5463

5564
// Store reference for cleanup
5665
(window as any).powersyncClient = db;

0 commit comments

Comments
 (0)