diff --git a/.circleci/test.sh b/.circleci/test.sh index b6ab1ca1..52e212de 100755 --- a/.circleci/test.sh +++ b/.circleci/test.sh @@ -7,7 +7,7 @@ set +e set +o pipefail EXIT_STATE=0 -MAX_AUTO_RETRY=5 +MAX_AUTO_RETRY=2 # inspired by https://unix.stackexchange.com/a/82602 retry () { diff --git a/src/component/plotly-dash-preview/constants.js b/src/component/plotly-dash-preview/constants.js index 255a51d2..9d58a5da 100644 --- a/src/component/plotly-dash-preview/constants.js +++ b/src/component/plotly-dash-preview/constants.js @@ -4,6 +4,7 @@ const micronsInInch = 25400 module.exports = { minInterval: 500, maxRenderingTries: 100, + maxPrintPDFTime: 50, pixelsInMicron: pixelsInInch / micronsInInch, sizeMapping: { 'A3': { 'width': 11.7 * pixelsInInch, 'height': 16.5 * pixelsInInch }, @@ -15,6 +16,7 @@ module.exports = { }, statusMsg: { 525: 'dash preview generation failed', - 526: 'dash preview generation timed out' + 526: 'dash preview generation timed out', + 527: 'dash preview pdf generation timed out' } } diff --git a/src/component/plotly-dash-preview/render.js b/src/component/plotly-dash-preview/render.js index 997c22c6..1eb2a361 100644 --- a/src/component/plotly-dash-preview/render.js +++ b/src/component/plotly-dash-preview/render.js @@ -75,10 +75,18 @@ function render (info, opts, sendToMain) { loaded().then(() => { // Move mouse outside the page to prevent hovering on figures contents.sendInputEvent({ type: 'mouseMove', x: -1, y: -1 }) + + // Close window if timeout is exceeded + // This is necessary because `printToPDF` sometimes never end + // https://github.com/electron/electron/issues/20634 + var timer = setTimeout(() => done(527), (info.timeOut || cst.maxPrintPDFTime) * 1000) + contents.printToPDF(info.pdfOptions, (err, pdfData) => { if (err) { + clearTimeout(timer) done(525) } else { + clearTimeout(timer) result.imgData = pdfData done() } diff --git a/test/unit/plotly-dash-preview_test.js b/test/unit/plotly-dash-preview_test.js index a35609e9..c42f9762 100644 --- a/test/unit/plotly-dash-preview_test.js +++ b/test/unit/plotly-dash-preview_test.js @@ -215,8 +215,8 @@ tap.test('render:', t => { }, {}, (errorCode, result) => { t.ok(win.webContents.printToPDF.calledOnce) t.ok(win.close.calledOnce) - t.equal(errorCode, 525, 'code') - t.equal(result.msg, 'dash preview generation failed', 'error msg') + t.equal(errorCode, 527, 'code') + t.equal(result.msg, 'dash preview pdf generation timed out', 'error msg') t.end() }) })