mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Fix tests by making sure to close optimistic file watchers.
If a test process does not explicitly call process.exit, pathwatcher watchers may keep it alive indefinitely (either that, or there's a bug with the persistent:false option to fs.watchFile). This accidental immortality can be prevented by explicitly closing all watchers when we no longer have any interest in file change notifications.
This commit is contained in:
@@ -130,7 +130,7 @@ function startNewWatcher(absPath) {
|
||||
|
||||
rewatch();
|
||||
|
||||
return {
|
||||
const entry = {
|
||||
callbacks,
|
||||
rewatch,
|
||||
|
||||
@@ -153,18 +153,38 @@ function startNewWatcher(absPath) {
|
||||
// can avoid tearing anything down.
|
||||
return;
|
||||
}
|
||||
|
||||
watchers[absPath] = null;
|
||||
|
||||
if (watcher) {
|
||||
watcher.close();
|
||||
watcher = null;
|
||||
}
|
||||
|
||||
unwatchFile(absPath, watchFileWrapper);
|
||||
entry.close();
|
||||
}, WATCHER_CLEANUP_DELAY_MS);
|
||||
},
|
||||
|
||||
close() {
|
||||
if (watchers[absPath] !== entry) return;
|
||||
watchers[absPath] = null;
|
||||
|
||||
if (watcherCleanupTimer) {
|
||||
clearTimeout(watcherCleanupTimer);
|
||||
watcherCleanupTimer = null;
|
||||
}
|
||||
|
||||
if (watcher) {
|
||||
watcher.close();
|
||||
watcher = null;
|
||||
}
|
||||
|
||||
unwatchFile(absPath, watchFileWrapper);
|
||||
}
|
||||
};
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
export function closeAllWatchers() {
|
||||
Object.keys(watchers).forEach(absPath => {
|
||||
const entry = watchers[absPath];
|
||||
if (entry) {
|
||||
entry.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function watchLibraryWatch(absPath, callback) {
|
||||
|
||||
@@ -13,6 +13,7 @@ var Profile = require('../tool-env/profile.js').Profile;
|
||||
var release = require('../packaging/release.js');
|
||||
import * as cordova from '../cordova';
|
||||
import { CordovaBuilder } from '../cordova/builder.js';
|
||||
import { closeAllWatchers } from "../fs/safe-watcher.js";
|
||||
|
||||
// Parse out s as if it were a bash command line.
|
||||
var bashParse = function (s) {
|
||||
@@ -980,6 +981,10 @@ _.extend(AppRunner.prototype, {
|
||||
break;
|
||||
}
|
||||
|
||||
// Allow the process to exit normally, since optimistic file watchers
|
||||
// may be keeping the event loop busy.
|
||||
closeAllWatchers();
|
||||
|
||||
// Giving up for good.
|
||||
self._cleanUpPromises();
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ var release = require('../../packaging/release.js');
|
||||
var catalog = require('../../packaging/catalog/catalog.js');
|
||||
var buildmessage = require('../../utils/buildmessage.js');
|
||||
var projectContextModule = require('../../project-context.js');
|
||||
var safeWatcher = require("../../fs/safe-watcher.js");
|
||||
|
||||
var lastTmpDir = null;
|
||||
var tmpDir = function () {
|
||||
@@ -156,4 +157,8 @@ Fiber(function () {
|
||||
console.log('\nBundle can be found at ' + lastTmpDir);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Allow the process to exit normally, since optimistic file watchers
|
||||
// may be keeping the event loop busy.
|
||||
safeWatcher.closeAllWatchers();
|
||||
}).run();
|
||||
|
||||
@@ -9,7 +9,7 @@ var catalog = require('../../packaging/catalog/catalog.js');
|
||||
var buildmessage = require('../../utils/buildmessage.js');
|
||||
var isopackets = require('../../tool-env/isopackets.js');
|
||||
var projectContextModule = require('../../project-context.js');
|
||||
|
||||
var safeWatcher = require("../../fs/safe-watcher.js");
|
||||
|
||||
var lastTmpDir = null;
|
||||
var tmpDir = function () {
|
||||
@@ -165,4 +165,8 @@ Fiber(function () {
|
||||
console.log('\nBundle can be found at ' + lastTmpDir);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Allow the process to exit normally, since optimistic file watchers
|
||||
// may be keeping the event loop busy.
|
||||
safeWatcher.closeAllWatchers();
|
||||
}).run();
|
||||
|
||||
Reference in New Issue
Block a user