From cb89a9e5d0c8be306dc1dae36bcc3f4dead13799 Mon Sep 17 00:00:00 2001 From: ylemkimon Date: Tue, 21 Aug 2018 13:04:05 +0900 Subject: [PATCH] Fix screenshotter race conditions (#1643) * Fix screenshotter race conditions * Update screenshotter.js * Update screenshotter.js --- dockers/screenshotter/screenshotter.js | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/dockers/screenshotter/screenshotter.js b/dockers/screenshotter/screenshotter.js index 1fef73c8..b137156f 100644 --- a/dockers/screenshotter/screenshotter.js +++ b/dockers/screenshotter/screenshotter.js @@ -475,24 +475,30 @@ function takeScreenshot(key) { const bufFile = path.join(outputDir, filenamePrefix + ".png"); let promise = fs.ensureDir(outputDir) - .then(fs.writeFile(bufFile, buf)); + .then(function() { + return fs.writeFile(bufFile, buf); + }); if (opts.diff) { promise = promise.then(fs.ensureDir(diffDir)) - .then(execFile("convert", [ - "-fill", "white", - // First image: saved screenshot in red - "(", baseFile, "-colorize", "100,0,0", ")", - // Second image: new screenshot in green - "(", bufFile, "-colorize", "0,80,0", ")", - // Composite them - "-compose", "darken", "-composite", - "-trim", // remove everything with the same color as the - // corners - diffFile, // output file name - ])); + .then(function() { + return execFile("convert", [ + "-fill", "white", + // First image: saved screenshot in red + "(", baseFile, "-colorize", "100,0,0", ")", + // Second image: new screenshot in green + "(", bufFile, "-colorize", "0,80,0", ")", + // Composite them + "-compose", "darken", "-composite", + "-trim", // remove everything with the same color as + // the corners + diffFile, // output file name + ]); + }); } if (!opts.new) { - promise = promise.then(fs.unlink(bufFile)); + promise = promise.then(function() { + return fs.unlink(bufFile); + }); } return promise; }