Skip to content

Commit

Permalink
perf: remove listener to fix log memory leak (#29939)
Browse files Browse the repository at this point in the history
* fix: remove listener to fix log memory leak

* updating changelog
  • Loading branch information
mschile authored Jul 30, 2024
1 parent f4052f1 commit dddd2d5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _Released 7/30/2024_

**Performance:**

- Fixed a memory leak with command logs with Test Replay enabled. Addressed in [#29939](https://github.com/cypress-io/cypress/pull/29939).
- Improved performance of `reduce` in a method within our proxy. Addressed in [#29887](https://github.com/cypress-io/cypress/pull/29887).

**Bugfixes:**
Expand Down
12 changes: 10 additions & 2 deletions packages/driver/cypress/e2e/cypress/log.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,9 @@ describe('src/cypress/log', function () {
let resolveDep
let changeEventsFlushed
let resolveChangeEventsFlushed
let timesFlushed = 0

before(function () {
changeEventsFlushed = false
this.cy = {
createSnapshot: cy.stub().returns({}),
}
Expand All @@ -494,19 +494,27 @@ describe('src/cypress/log', function () {
// spies / stubs get cleared between tests, so
// a wholesale fn replacement is called for
log.fireChangeEvent.flush = function () {
timesFlushed++
resolveChangeEventsFlushed(true)
}

resolveDep(log)
})

it('flushes change events on test:after:run', function () {
cy.wrap(dependency).then((prevLog) => {
cy.wrap(dependency).then(() => {
cy.wrap(changeEventsFlushed).then((flushed) => {
expect(flushed).to.be.true
expect(timesFlushed).to.eq(1)
})
})
})

it('does not flush again on test:after:run', function () {
// flush should not have been called again
// since the test:after:run listener should've been removed
expect(timesFlushed).to.eq(1)
})
})

context('timestamps', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cypress/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class Log {
this.fireChangeEvent = _.debounce(fireChangeEvent, 4)

if (config('protocolEnabled')) {
Cypress.on('test:after:run', () => {
Cypress.once('test:after:run', () => {
this.fireChangeEvent.flush()
})
}
Expand Down

3 comments on commit dddd2d5

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dddd2d5 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.2/linux-x64/develop-dddd2d55d301f37854f5be1e3f9fc9bce036854c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dddd2d5 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.2/win32-x64/develop-dddd2d55d301f37854f5be1e3f9fc9bce036854c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on dddd2d5 Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.13.2/darwin-x64/develop-dddd2d55d301f37854f5be1e3f9fc9bce036854c/cypress.tgz

Please sign in to comment.