-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,155 additions
and
101 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
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
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
7 changes: 7 additions & 0 deletions
7
packages/signals/signals-integration-tests/src/tests/performance/index-page.ts
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,7 @@ | ||
import { BasePage } from '../../helpers/base-page-object' | ||
|
||
export class IndexPage extends BasePage { | ||
constructor() { | ||
super(`/performance/index.html`) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/signals/signals-integration-tests/src/tests/performance/index.html
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,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<script src="../../../dist/signals-vanilla.bundle.js"></script> | ||
<!-- Dummy favicon --> | ||
<link rel="icon" href="data:;base64,iVBORw0KGgo="> | ||
</head> | ||
|
||
<body> | ||
<div id="test-container"></div> | ||
</body> | ||
|
||
</html> |
76 changes: 76 additions & 0 deletions
76
packages/signals/signals-integration-tests/src/tests/performance/memory-leak.test.ts
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,76 @@ | ||
import { test } from '@playwright/test' | ||
import { IndexPage } from './index-page' | ||
import { sleep } from '@segment/analytics-core' | ||
|
||
declare global { | ||
interface Performance { | ||
memory: { | ||
usedJSHeapSize: number | ||
totalJSHeapSize: number | ||
} | ||
} | ||
} | ||
|
||
const basicEdgeFn = ` | ||
// this is a process signal function | ||
const processSignal = (signal) => { | ||
if (signal.type === 'interaction') { | ||
const eventName = signal.data.eventType + ' ' + '[' + signal.type + ']' | ||
analytics.track(eventName, signal.data) | ||
} | ||
}` | ||
|
||
let indexPage: IndexPage | ||
|
||
test.beforeEach(async ({ page }) => { | ||
indexPage = await new IndexPage().loadAndWait(page, basicEdgeFn) | ||
}) | ||
|
||
test('memory leak', async ({ page }) => { | ||
await indexPage.waitForSignalsApiFlush() | ||
const ALLOWED_GROWTH = 1.1 | ||
const getMemoryUsage = (): Promise<number> => | ||
page.evaluate(() => { | ||
return performance.memory.usedJSHeapSize | ||
}) | ||
|
||
const firstMemory = await getMemoryUsage() | ||
|
||
// add nodes | ||
await page.evaluate(() => { | ||
const target = document.getElementById('test-container')! | ||
const NODE_COUNT = 2000 | ||
for (let i = 0; i < NODE_COUNT; i++) { | ||
const newNode = document.createElement('input') | ||
newNode.type = 'text' | ||
newNode.value = Math.random().toString() | ||
target.appendChild(newNode) | ||
} | ||
}) | ||
|
||
await sleep(3000) | ||
|
||
// remove all the nodes | ||
await page.evaluate(() => { | ||
const target = document.getElementById('test-container')! | ||
while (target.firstChild) { | ||
target.removeChild(target.firstChild) | ||
} | ||
}) | ||
|
||
// Analyze memory usage | ||
await sleep(3000) | ||
const lastMemory = await getMemoryUsage() | ||
|
||
// Allow some fluctuation, but fail if there's a significant memory increase | ||
if (lastMemory > firstMemory * ALLOWED_GROWTH) { | ||
throw new Error( | ||
`Memory leak detected! Initial: ${firstMemory}, Final: ${lastMemory}. Threshold` | ||
) | ||
} else { | ||
console.log( | ||
'Memory leak test passed!', | ||
`initial: ${firstMemory}, final: ${lastMemory}, allowed growth: ${ALLOWED_GROWTH}` | ||
) | ||
} | ||
}) |
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
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
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
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
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
Oops, something went wrong.