forked from stoplightio/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: stoplightio#1881 fixed memory leak for validation
- Loading branch information
Showing
8 changed files
with
117 additions
and
13 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
43 changes: 43 additions & 0 deletions
43
packages/http/src/__tests__/memory-leak-prevention.spec.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,43 @@ | ||
import { createClientFromOperations, PrismHttp } from '../client'; | ||
import { httpOperations } from './fixtures'; | ||
import { createTestLogger } from './test-helpers'; | ||
|
||
describe('Checks if memory leaks', () => { | ||
function round(client: PrismHttp) { | ||
return client.post( | ||
'/todos?overwrite=yes', | ||
{ | ||
name: 'some name', | ||
completed: false, | ||
}, | ||
{ headers: { 'x-todos-publish': '2021-09-21T09:48:48.108Z' } } | ||
); | ||
} | ||
|
||
it('when handling 5k of requests', () => { | ||
const logger = createTestLogger(); | ||
const client = createClientFromOperations(httpOperations, { | ||
validateRequest: true, | ||
validateResponse: true, | ||
checkSecurity: true, | ||
errors: true, | ||
mock: { | ||
dynamic: false, | ||
}, | ||
logger, | ||
}); | ||
|
||
round(client); | ||
const baseMemoryUsage = process.memoryUsage().heapUsed; | ||
|
||
for (let i = 0; i < 5000; i++) { | ||
round(client); | ||
if (i % 100 === 0) { | ||
global.gc(); | ||
} | ||
} | ||
|
||
global.gc(); | ||
expect(process.memoryUsage().heapUsed).toBeLessThanOrEqual(baseMemoryUsage * 1.02); | ||
}); | ||
}); |
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 @@ | ||
import * as pino from 'pino'; | ||
|
||
/** | ||
* Creates special instance of pino logger that prevent collecting or logging anything | ||
* Unfortunately disabled logger didn't work | ||
*/ | ||
export function createTestLogger() { | ||
const logger = pino({ | ||
enabled: false, | ||
}); | ||
|
||
logger.success = logger.info; | ||
return logger; | ||
} |
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