Skip to content

Commit

Permalink
Split up memory tests (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebrody authored Jan 22, 2025
1 parent 4cbb375 commit a4105f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
8 changes: 8 additions & 0 deletions react/test/memory_article_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { californiaArticleThreshold, getJSHeapSize } from './memory_test_utils'
import { urbanstatsFixture } from './test_utils'

urbanstatsFixture('california', '/article.html?longname=California%2C+USA&s=GczH23sVhzZkQid')

test('under memory limit california', async (t) => {
await t.expect(await getJSHeapSize(t)).lt(californiaArticleThreshold)
})
8 changes: 8 additions & 0 deletions react/test/memory_home_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getJSHeapSize, homePageThreshold } from './memory_test_utils'
import { urbanstatsFixture } from './test_utils'

urbanstatsFixture('home page', '/')

test('under memory limit home page', async (t) => {
await t.expect(await getJSHeapSize(t)).lt(homePageThreshold)
})
23 changes: 0 additions & 23 deletions react/test/memory_test.ts

This file was deleted.

14 changes: 14 additions & 0 deletions react/test/memory_test_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Since testcafe accumulates memory in the CI, each memory test must be run in its own test file
export async function getJSHeapSize(t: TestController): Promise<number> {
await t.wait(1000) // Wait for page to load
const cdpSession = await t.getCurrentCDPSession()
await cdpSession.HeapProfiler.collectGarbage()
await t.wait(1000) // Wait for garbage collect
const bytesUsed = await t.eval(() => (performance as unknown as { memory: { usedJSHeapSize: number } }).memory.usedJSHeapSize) as number
console.warn(`Bytes used: ${bytesUsed}`)
return bytesUsed
}

export const homePageThreshold = 35_000_000
export const compressedSearchIndexSize = 3_000_000
export const californiaArticleThreshold = 57_000_000

0 comments on commit a4105f6

Please sign in to comment.