mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Screenshotting] Revive PDF maker jest tests (#128356)
* make pdf worker tests regular jest tests * testing out as jest integration test again * added a lot of debugging logs - revert this * only run this test in the suite * Revert "added a lot of debugging logs - revert this" This reverts commit5f4abe760d
. * Revert "only run this test in the suite" This reverts commit0b0ea80e11
. * update test and remove old comment * move code around * revert this: addded logs to check if isMainThread * try to pretend we are on the main thread, yikes * hack, do not check isMainThread... * remove logs, reinstate the isMainThread check and update jest tests parallel * remove unnecessary mock Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
f4f145dedc
commit
ee443e91e2
3 changed files with 20 additions and 20 deletions
|
@ -13,7 +13,7 @@ exitCode=0
|
|||
while read -r config; do
|
||||
if [ "$((i % JOB_COUNT))" -eq "$JOB" ]; then
|
||||
echo "--- $ node scripts/jest --config $config"
|
||||
node --max-old-space-size=14336 ./node_modules/.bin/jest --config="$config" --runInBand --coverage=false --passWithNoTests
|
||||
node --max-old-space-size=14336 ./scripts/jest --config="$config" --runInBand --coverage=false --passWithNoTests
|
||||
lastCode=$?
|
||||
|
||||
if [ $lastCode -ne 0 ]; then
|
||||
|
|
|
@ -19,7 +19,7 @@ const imageBase64 = Buffer.from(
|
|||
'base64'
|
||||
);
|
||||
|
||||
describe.skip('PdfMaker', () => {
|
||||
describe('PdfMaker', () => {
|
||||
let layout: ReturnType<typeof createMockLayout>;
|
||||
let pdf: PdfMaker;
|
||||
let logger: ReturnType<typeof loggingSystemMock.createLogger>;
|
||||
|
@ -41,14 +41,14 @@ describe.skip('PdfMaker', () => {
|
|||
});
|
||||
|
||||
describe('worker', () => {
|
||||
/**
|
||||
* Leave this test skipped! It is a proof-of-concept for demonstrating that
|
||||
* we correctly handle a worker OOM error. Due to the variability of when
|
||||
* Node will terminate the worker thread for exceeding resource
|
||||
* limits we cannot guarantee this test will always execute in a reasonable
|
||||
* amount of time.
|
||||
*/
|
||||
it.skip('should report when the PDF worker runs out of memory instead of crashing the main thread', async () => {
|
||||
/**
|
||||
* Leave this test skipped! It is a proof-of-concept for demonstrating that
|
||||
* we correctly handle a worker OOM error. Due to the variability of when
|
||||
* Node will terminate the worker thread for exceeding resource
|
||||
* limits we cannot guarantee this test will always execute in a reasonable
|
||||
* amount of time.
|
||||
*/
|
||||
const leakyMaker = new (class MemoryLeakPdfMaker extends PdfMaker {
|
||||
// From local testing:
|
||||
// OOMs after 456.486 seconds with high young generation size
|
||||
|
@ -60,14 +60,14 @@ describe.skip('PdfMaker', () => {
|
|||
await expect(leakyMaker.generate()).rejects.toBeInstanceOf(errors.PdfWorkerOutOfMemoryError);
|
||||
});
|
||||
|
||||
it.skip('restarts the PDF worker if it crashes', async () => {
|
||||
it('restarts the PDF worker if it crashes', async () => {
|
||||
const buggyMaker = new (class BuggyPdfMaker extends PdfMaker {
|
||||
protected workerModulePath = path.resolve(__dirname, './buggy_worker.js');
|
||||
})(layout, undefined, logger);
|
||||
|
||||
await expect(buggyMaker.generate()).rejects.toEqual(new Error('This is a bug'));
|
||||
await expect(buggyMaker.generate()).rejects.toEqual(new Error('This is a bug'));
|
||||
await expect(buggyMaker.generate()).rejects.toEqual(new Error('This is a bug'));
|
||||
await expect(buggyMaker.generate()).rejects.toThrowError(new Error('This is a bug'));
|
||||
await expect(buggyMaker.generate()).rejects.toThrowError(new Error('This is a bug'));
|
||||
await expect(buggyMaker.generate()).rejects.toThrowError(new Error('This is a bug'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -202,13 +202,7 @@ export class PdfMaker {
|
|||
reject(workerError);
|
||||
}
|
||||
});
|
||||
this.worker.on('exit', () => {}); // do nothing on errors
|
||||
|
||||
// Send the initial request
|
||||
const generatePdfRequest: GeneratePdfRequest = {
|
||||
data: this.getGeneratePdfRequestData(),
|
||||
};
|
||||
myPort.postMessage(generatePdfRequest);
|
||||
this.worker.on('exit', () => {});
|
||||
|
||||
// We expect one message from the worker generating the PDF buffer.
|
||||
myPort.on('message', ({ error, data }: GeneratePdfResponse) => {
|
||||
|
@ -223,6 +217,12 @@ export class PdfMaker {
|
|||
this.pageCount = data.metrics.pages;
|
||||
resolve(data.buffer);
|
||||
});
|
||||
|
||||
// Send the request
|
||||
const generatePdfRequest: GeneratePdfRequest = {
|
||||
data: this.getGeneratePdfRequestData(),
|
||||
};
|
||||
myPort.postMessage(generatePdfRequest);
|
||||
});
|
||||
} finally {
|
||||
await this.cleanupWorker();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue