Skip to content

Commit a1279be

Browse files
committed
test(assets): resolve the refresh before the stale loadMore in race tests
Two of the flat-output race tests resolved the loadMore before the refresh. In that ordering a successful refresh overwrites every piece of state the stale page touched, so both tests passed with the epoch guard removed and proved nothing about it. Flip both to resolve the refresh first, where the stale continuation lands on an already-reset list, and retarget the first test's assertion to the offset (observed via the next request's `offset` argument) so it covers the double-advance axis rather than duplicating the sibling test's list check. Removing the epoch guard now fails all four guard tests; previously two.
1 parent 7369fda commit a1279be

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/stores/assetsStore.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,7 +2410,7 @@ describe('assetsStore - Flat Output Assets (cloud-only)', () => {
24102410
expect(store.flatOutputAssets.map((a) => a.id)).toEqual(['fresh-1'])
24112411
})
24122412

2413-
it('a stale loadMore that resolves before the refresh does not corrupt seenIds', async () => {
2413+
it('does not double-advance the offset with a discarded loadMore page', async () => {
24142414
const { store } = await setupStoreWithFirstPage()
24152415
const loadMorePage = deferredPage()
24162416
const refreshPage = deferredPage()
@@ -2422,23 +2422,24 @@ describe('assetsStore - Flat Output Assets (cloud-only)', () => {
24222422
const loadMoreResult = store.loadMoreFlatOutputs()
24232423
const refreshResult = store.updateFlatOutputs()
24242424

2425-
// The stale loadMore settles first, before the refresh has replaced the
2426-
// list. Its page must be discarded rather than folded into seenIds.
2427-
loadMorePage.resolve(makePage([makeAsset('extra-1', 'extra.png')]))
24282425
refreshPage.resolve(
24292426
makePage([makeAsset('fresh-1', 'fresh.png')], { hasMore: true })
24302427
)
2428+
loadMorePage.resolve(makePage([makeAsset('extra-1', 'extra.png')]))
24312429
await Promise.all([loadMoreResult, refreshResult])
24322430

2433-
expect(store.flatOutputAssets.map((a) => a.id)).toEqual(['fresh-1'])
2434-
2435-
// If the discarded loadMore had leaked 'extra-1' into seenIds, this
2436-
// legitimate next page would be filtered out and never shown.
2431+
// The refreshed list holds one asset, so the next page starts at 1. A
2432+
// discarded page that still advanced the offset would skip a row here.
24372433
vi.mocked(assetService.getAssetsPageByTag).mockResolvedValueOnce(
24382434
makePage([makeAsset('extra-1', 'extra.png')])
24392435
)
24402436
await store.loadMoreFlatOutputs()
24412437

2438+
expect(assetService.getAssetsPageByTag).toHaveBeenLastCalledWith(
2439+
'output',
2440+
true,
2441+
{ limit: FLAT_OUTPUT_PAGE_SIZE, offset: 1 }
2442+
)
24422443
expect(store.flatOutputAssets.map((a) => a.id)).toEqual([
24432444
'fresh-1',
24442445
'extra-1'
@@ -2457,12 +2458,12 @@ describe('assetsStore - Flat Output Assets (cloud-only)', () => {
24572458
const loadMoreResult = store.loadMoreFlatOutputs()
24582459
const refreshResult = store.updateFlatOutputs()
24592460

2460-
loadMorePage.resolve(
2461-
makePage([makeAsset('extra-1', 'extra.png')], { hasMore: true })
2462-
)
24632461
refreshPage.resolve(
24642462
makePage([makeAsset('fresh-1', 'fresh.png')], { hasMore: false })
24652463
)
2464+
loadMorePage.resolve(
2465+
makePage([makeAsset('extra-1', 'extra.png')], { hasMore: true })
2466+
)
24662467
await Promise.all([loadMoreResult, refreshResult])
24672468

24682469
expect(store.flatOutputAssets.map((a) => a.id)).toEqual(['fresh-1'])

0 commit comments

Comments
 (0)