From ec02117232f3e1b4b8010dd011dbb38cffaf0dc2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 6 Jun 2018 23:22:50 +0200 Subject: [PATCH] test: add fs.watchFile() + worker.terminate() test Refs: https://github.com/nodejs/node/pull/21093#discussion_r193563156 PR-URL: https://github.com/nodejs/node/pull/21179 Reviewed-By: Anatoli Papirovski Reviewed-By: Jeremiah Senkpiel Reviewed-By: Yuta Hiroto Reviewed-By: Benjamin Gruenbaum Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat Reviewed-By: Minwoo Jung Reviewed-By: James M Snell --- test/parallel/test-worker-fs-stat-watcher.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/parallel/test-worker-fs-stat-watcher.js diff --git a/test/parallel/test-worker-fs-stat-watcher.js b/test/parallel/test-worker-fs-stat-watcher.js new file mode 100644 index 00000000000000..b58d43d0cfa8ea --- /dev/null +++ b/test/parallel/test-worker-fs-stat-watcher.js @@ -0,0 +1,18 @@ +// Flags: --experimental-worker +'use strict'; +const common = require('../common'); +const { Worker, parentPort } = require('worker_threads'); +const fs = require('fs'); + +// Checks that terminating Workers does not crash the process if fs.watchFile() +// has active handles. + +// Do not use isMainThread so that this test itself can be run inside a Worker. +if (!process.env.HAS_STARTED_WORKER) { + process.env.HAS_STARTED_WORKER = 1; + const worker = new Worker(__filename); + worker.on('message', common.mustCall(() => worker.terminate())); +} else { + fs.watchFile(__filename, () => {}); + parentPort.postMessage('running'); +}