Skip to content

Commit

Permalink
test(ssr): add deadlock scenario using dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
shYkiSto committed Dec 20, 2023
1 parent 5684fcd commit 3dcb87b
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
16 changes: 13 additions & 3 deletions playground/ssr/__tests__/ssr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ test(`circular dependencies modules doesn't throw`, async () => {
)
})

test(`deadlock doesn't happen`, async () => {
await page.goto(`${url}/forked-deadlock`)
test(`deadlock doesn't happen for static imports`, async () => {
await page.goto(`${url}/forked-deadlock-static-imports`)

expect(await page.textContent('.forked-deadlock')).toMatch('rendered')
expect(await page.textContent('.forked-deadlock-static-imports')).toMatch(
'rendered',
)
})

test(`deadlock doesn't happen for dynamic imports`, async () => {
await page.goto(`${url}/forked-deadlock-dynamic-imports`)

expect(await page.textContent('.forked-deadlock-dynamic-imports')).toMatch(
'rendered',
)
})

test('should restart ssr', async () => {
Expand Down
15 changes: 12 additions & 3 deletions playground/ssr/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { escapeHtml } from './utils'
const pathRenderers = {
'/': renderRoot,
'/circular-dep': renderCircularDep,
'/forked-deadlock': renderForkedDeadlock,
'/forked-deadlock-static-imports': renderForkedDeadlockStaticImports,
'/forked-deadlock-dynamic-imports': renderForkedDeadlockDynamicImports,
}

export async function render(url, rootDir) {
Expand Down Expand Up @@ -34,8 +35,16 @@ async function renderCircularDep(rootDir) {
return `<div class="circ-dep-init">${escapeHtml(getValueAB())}</div>`
}

async function renderForkedDeadlock(rootDir) {
async function renderForkedDeadlockStaticImports(rootDir) {
const { commonModuleExport } = await import('./forked-deadlock/common-module')
commonModuleExport()
return `<div class="forked-deadlock">rendered</div>`
return `<div class="forked-deadlock-static-imports">rendered</div>`
}

async function renderForkedDeadlockDynamicImports(rootDir) {
const { commonModuleExport } = await import(
'./forked-deadlock/dynamic-imports/common-module'
)
await commonModuleExport()
return `<div class="forked-deadlock-dynamic-imports">rendered</div>`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* module H
*/
export async function commonModuleExport() {
const [{ stuckModuleExport }, { deadlockfuseModuleExport }] =
await Promise.all([
import('./stuck-module'),
import('./deadlock-fuse-module'),
])

stuckModuleExport()
deadlockfuseModuleExport()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { fuseStuckBridgeModuleExport } from './fuse-stuck-bridge-module'

/**
* module A
*/
export function deadlockfuseModuleExport() {
fuseStuckBridgeModuleExport()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { stuckModuleExport } from './stuck-module'

/**
* module C
*/
export function fuseStuckBridgeModuleExport() {
stuckModuleExport()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { deadlockfuseModuleExport } from './deadlock-fuse-module'

/**
* module Y
*/
export function middleModuleExport() {
void deadlockfuseModuleExport
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { middleModuleExport } from './middle-module'

/**
* module X
*/
export function stuckModuleExport() {
middleModuleExport()
}

0 comments on commit 3dcb87b

Please sign in to comment.