Skip to content

Commit

Permalink
adding back unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile committed Jan 23, 2023
1 parent 8347baa commit 84c062e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
20 changes: 10 additions & 10 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ jobs:
path: /tmp/cypress
- store-npm-logs

memory-driver-tests:
driver-integration-memory-tests:
<<: *defaults
parameters:
<<: *defaultsParameters
Expand Down Expand Up @@ -2431,7 +2431,7 @@ linux-x64-workflow: &linux-x64-workflow
context: test-runner:cypress-record-key
requires:
- build
- memory-driver-tests:
- driver-integration-memory-tests:
requires:
- build
- run-frontend-shared-component-tests-chrome:
Expand Down Expand Up @@ -2675,8 +2675,8 @@ linux-arm64-workflow: &linux-arm64-workflow
resource_class: arm.medium
requires:
- linux-arm64-build
- memory-driver-tests:
name: linux-arm64-memory-driver-tests
- driver-integration-memory-tests:
name: linux-arm64-driver-integration-memory-tests
executor: linux-arm64
resource_class: arm.medium
requires:
Expand Down Expand Up @@ -2721,8 +2721,8 @@ darwin-x64-workflow: &darwin-x64-workflow
resource_class: macos.x86.medium.gen2
requires:
- darwin-x64-build
- memory-driver-tests:
name: darwin-x64-memory-driver-tests
- driver-integration-memory-tests:
name: darwin-x64-driver-integration-memory-tests
executor: mac
resource_class: macos.x86.medium.gen2
requires:
Expand Down Expand Up @@ -2760,8 +2760,8 @@ darwin-arm64-workflow: &darwin-arm64-workflow
resource_class: cypress-io/latest_m1
requires:
- darwin-arm64-build
- memory-driver-tests:
name: darwin-arm64-memory-driver-tests
- driver-integration-memory-tests:
name: darwin-arm64-driver-integration-memory-tests
executor: darwin-arm64
resource_class: cypress-io/latest_m1
requires:
Expand Down Expand Up @@ -2828,8 +2828,8 @@ windows-workflow: &windows-workflow
resource_class: windows.large
requires:
- windows-build
- memory-driver-tests:
name: windows-memory-driver-tests
- driver-integration-memory-tests:
name: windows-driver-integration-memory-tests
executor: windows
resource_class: windows.large
requires:
Expand Down
11 changes: 8 additions & 3 deletions packages/server/lib/browsers/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export type MemoryHandler = {
/**
* Algorithm:
*
* When the test runs starts:
* When the spec run starts:
* 1. set total mem limit for the container/host by reading off cgroup memory limits (if available) otherwise use os.totalmem()
* 2. set js heap size limit by reading off the browser
* 3. turn on memory profiler
*
* On a defined interval (e.g. 1s):
* 1. set current mem available for the container/host by reading off cgroup memory usage (if available) otherwise use si.mem().available
Expand All @@ -54,7 +56,10 @@ export type MemoryHandler = {
* 4. calc % of memory used, current renderer mem usage / max avail render mem
*
* Before each test:
* 1. if that exceeds the defined memory threshold percentage (e.g. 50%) do a GC
* 1. if any interval exceeded the defined memory threshold (e.g. 50%), do a GC
*
* After the spec run ends:
* 1. turn off memory profiler
*/

/**
Expand Down Expand Up @@ -221,7 +226,7 @@ export const calculateMemoryStats: () => Promise<void> = measure(async () => {
const maxAvailableRendererMemory = Math.min(jsHeapSizeLimit, currentAvailableMemory + rendererProcessMemRss)

const rendererUsagePercentage = (rendererProcessMemRss / maxAvailableRendererMemory) * 100
// if we're using more than MEMORY_THRESHOLD_PERCENTAGE of the available memory,
// if the renderer's memory is above the MEMORY_THRESHOLD_PERCENTAGE, we should collect garbage on the next test
const shouldCollectGarbage = rendererUsagePercentage >= MEMORY_THRESHOLD_PERCENTAGE && !SKIP_GC

// if we should collect garbage, set the flag to true so we can collect garbage on the next test
Expand Down
17 changes: 10 additions & 7 deletions packages/server/test/unit/browsers/memory/memory_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ describe('lib/browsers/memory', () => {

before(() => {
delete require.cache[require.resolve('../../../../lib/browsers/memory')]
process.env.CYPRESS_INTERNAL_MEMORY_SAVE_STATS = 'true'

memory = require('../../../../lib/browsers/memory')
})

beforeEach(() => {
sinon.useFakeTimers()
process.env.CYPRESS_INTERNAL_MEMORY_SAVE_STATS = 'true'

memory = require('../../../../lib/browsers/memory')
})

afterEach(async () => {
Expand Down Expand Up @@ -161,6 +161,7 @@ describe('lib/browsers/memory', () => {

it('collects memory when renderer process is greater than the custom threshold', async () => {
process.env.CYPRESS_INTERNAL_MEMORY_THRESHOLD_PERCENTAGE = '25'
process.env.CYPRESS_INTERNAL_MEMORY_SAVE_STATS = 'true'

const memory = proxyquire('../lib/browsers/memory', {})

Expand Down Expand Up @@ -543,9 +544,11 @@ describe('lib/browsers/memory', () => {
})

it('uses the existing process id to obtain the memory usage', async () => {
process.env.CYPRESS_INTERNAL_MEMORY_SAVE_STATS = 'true'

const pidStub = sinon.stub().resolves({ memory: 2000 })

const memory = proxyquire('../lib/browsers/memory', { pidusage: pidStub })
const memory: typeof import('../../../../lib/browsers/memory') = proxyquire('../lib/browsers/memory', { pidusage: pidStub })

const automation = sinon.createStubInstance(Automation)
const gcStub = automation.request.withArgs('collect:garbage').resolves()
Expand Down Expand Up @@ -621,7 +624,7 @@ describe('lib/browsers/memory', () => {
expect(memory.default.getMemoryStats()).to.deep.eql(expected)
})

it('collects memory when a previous checkMemory call goes over the threshold', async () => {
it('collects memory when a previous interval call goes over the threshold', async () => {
const automation = sinon.createStubInstance(Automation)
const gcStub = automation.request.withArgs('collect:garbage').resolves()
const mockHandler = {
Expand All @@ -632,8 +635,8 @@ describe('lib/browsers/memory', () => {
sinon.stub(memory, 'getJsHeapSizeLimit').resolves(100)
sinon.stub(memory, 'getMemoryHandler').resolves(mockHandler)
sinon.stub(memory, 'getRendererMemoryUsage')
.onFirstCall().resolves(75)
.onSecondCall().resolves(25)
.onFirstCall().resolves(75) // above threshold
.onSecondCall().resolves(25) // below threshold

await memory.default.startProfiling(automation, { fileName: 'memory_spec' })
await memory.default.gatherMemoryStats()
Expand Down

0 comments on commit 84c062e

Please sign in to comment.