Skip to content

Commit cd049a4

Browse files
committed
test: fix macos integ tests failures due to stray watch event timings
1 parent 308dfd6 commit cd049a4

File tree

10 files changed

+47
-39
lines changed

10 files changed

+47
-39
lines changed

dist/phoenix-fs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ function _watch(ws, metadata) {
321321

322322
// Filter function to integrate with chokidar
323323
function isIgnored(pathToFilter) {
324-
console.log(`Watching: ${fullPathToWatch} Filtering: ${pathToFilter}`);
325324
if(fullPathToWatch === pathToFilter) {
326325
// if we are watching a file directly given file name, we don't run it though gitignore.
327326
// also we cant get relative path of gitignore with respect to a file as root.
@@ -331,15 +330,16 @@ function _watch(ws, metadata) {
331330
// Do not watch if the path given is not a subpath of our watched path.
332331
// if we are watching a file directly given file name, Then we get an isignored call for the parent
333332
// dir from chokidar.
333+
console.log(`PhoenixFS: Watching: ${fullPathToWatch} Filtered path: ${pathToFilter}`);
334334
return true;
335335
}
336336
const relativePath = path.relative(fullPathToWatch, pathToFilter);
337337
if(anymatch(ignoredPaths, pathToFilter)){
338-
debugMode && console.log("ignored watch path: ", pathToFilter, "rel: ",relativePath);
338+
debugMode && console.log("PhoenixFS: anymatch ignored watch path: ", pathToFilter, "rel: ", relativePath);
339339
return true;
340340
}
341341
if(relativePath && gitignore.ignores(relativePath)){
342-
debugMode && console.log("ignored watch gitIgnore path: ", pathToFilter, "rel: ",relativePath);
342+
debugMode && console.log("PhoenixFS: gitignore ignored watch gitIgnore path: ", pathToFilter, "rel: ",relativePath);
343343
return true;
344344
} else {
345345
return false;
@@ -438,14 +438,14 @@ function processWSCommand(ws, metadata, dataBuffer) {
438438
_unwatch(ws, metadata);
439439
return;
440440
case WS_COMMAND.LARGE_DATA_SOCKET_ANNOUNCE:
441-
console.log("Large Data Transfer Socket established, socket Group: ", metadata.socketGroupID);
441+
console.log("PhoenixFS: Large Data Transfer Socket established, socket Group: ", metadata.socketGroupID);
442442
ws.isLargeData = true;
443443
ws.socketGroupID = metadata.socketGroupID;
444444
largeDataSocketMap[metadata.socketGroupID] = ws;
445445
_sendResponse(ws, metadata, {}, dataBuffer);
446446
return;
447447
case WS_COMMAND.CONTROL_SOCKET_ANNOUNCE:
448-
console.log("Control Socket established, socket Group:", metadata.socketGroupID);
448+
console.log("PhoenixFS: Control Socket established, socket Group:", metadata.socketGroupID);
449449
ws.isLargeData = false;
450450
ws.socketGroupID = metadata.socketGroupID;
451451
controlSocketMap[metadata.socketGroupID] = ws;
@@ -484,12 +484,12 @@ function CreatePhoenixFsServer(server, wssPath = "/phoenixFS") {
484484

485485
// Set up a connection listener
486486
wss.on('connection', (ws) => {
487-
console.log('Websocket Client connected');
487+
console.log('PhoenixFS: Websocket Client connected');
488488
ws.binaryType = 'arraybuffer';
489489

490490
// Listen for messages from the client
491491
ws.on('message', (message) => {
492-
debugMode && console.log(`Received message ${message} of size: ${message.byteLength}, type: ${typeof message}, isArrayBuffer: ${message instanceof ArrayBuffer}, isBuffer: ${Buffer.isBuffer(message)}`);
492+
debugMode && console.log(`PhoenixFS: Received message ${message} of size: ${message.byteLength}, type: ${typeof message}, isArrayBuffer: ${message instanceof ArrayBuffer}, isBuffer: ${Buffer.isBuffer(message)}`);
493493
processWebSocketMessage(ws, message);
494494
});
495495

@@ -499,10 +499,10 @@ function CreatePhoenixFsServer(server, wssPath = "/phoenixFS") {
499499
ws.on('close', () => {
500500
if(ws.isLargeData && ws.socketGroupID && largeDataSocketMap[ws.socketGroupID] === ws){
501501
delete largeDataSocketMap[ws.socketGroupID];
502-
console.log('Websocket Client disconnected: Large data Socket');
502+
console.log('PhoenixFS: Websocket Client disconnected: Large data Socket');
503503
} else if(!ws.isLargeData && ws.socketGroupID && controlSocketMap[ws.socketGroupID] === ws){
504504
delete controlSocketMap[ws.socketGroupID];
505-
console.log('Websocket Client disconnected: control Socket');
505+
console.log('PhoenixFS: Websocket Client disconnected: control Socket');
506506
}
507507
});
508508
});

dist/virtualfs.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/virtualfs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/node-src/phoenix-fs.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ function _watch(ws, metadata) {
321321

322322
// Filter function to integrate with chokidar
323323
function isIgnored(pathToFilter) {
324-
console.log(`Watching: ${fullPathToWatch} Filtering: ${pathToFilter}`);
325324
if(fullPathToWatch === pathToFilter) {
326325
// if we are watching a file directly given file name, we don't run it though gitignore.
327326
// also we cant get relative path of gitignore with respect to a file as root.
@@ -331,15 +330,16 @@ function _watch(ws, metadata) {
331330
// Do not watch if the path given is not a subpath of our watched path.
332331
// if we are watching a file directly given file name, Then we get an isignored call for the parent
333332
// dir from chokidar.
333+
console.log(`PhoenixFS: Watching: ${fullPathToWatch} Filtered path: ${pathToFilter}`);
334334
return true;
335335
}
336336
const relativePath = path.relative(fullPathToWatch, pathToFilter);
337337
if(anymatch(ignoredPaths, pathToFilter)){
338-
debugMode && console.log("ignored watch path: ", pathToFilter, "rel: ",relativePath);
338+
debugMode && console.log("PhoenixFS: anymatch ignored watch path: ", pathToFilter, "rel: ", relativePath);
339339
return true;
340340
}
341341
if(relativePath && gitignore.ignores(relativePath)){
342-
debugMode && console.log("ignored watch gitIgnore path: ", pathToFilter, "rel: ",relativePath);
342+
debugMode && console.log("PhoenixFS: gitignore ignored watch gitIgnore path: ", pathToFilter, "rel: ",relativePath);
343343
return true;
344344
} else {
345345
return false;
@@ -438,14 +438,14 @@ function processWSCommand(ws, metadata, dataBuffer) {
438438
_unwatch(ws, metadata);
439439
return;
440440
case WS_COMMAND.LARGE_DATA_SOCKET_ANNOUNCE:
441-
console.log("Large Data Transfer Socket established, socket Group: ", metadata.socketGroupID);
441+
console.log("PhoenixFS: Large Data Transfer Socket established, socket Group: ", metadata.socketGroupID);
442442
ws.isLargeData = true;
443443
ws.socketGroupID = metadata.socketGroupID;
444444
largeDataSocketMap[metadata.socketGroupID] = ws;
445445
_sendResponse(ws, metadata, {}, dataBuffer);
446446
return;
447447
case WS_COMMAND.CONTROL_SOCKET_ANNOUNCE:
448-
console.log("Control Socket established, socket Group:", metadata.socketGroupID);
448+
console.log("PhoenixFS: Control Socket established, socket Group:", metadata.socketGroupID);
449449
ws.isLargeData = false;
450450
ws.socketGroupID = metadata.socketGroupID;
451451
controlSocketMap[metadata.socketGroupID] = ws;
@@ -484,12 +484,12 @@ function CreatePhoenixFsServer(server, wssPath = "/phoenixFS") {
484484

485485
// Set up a connection listener
486486
wss.on('connection', (ws) => {
487-
console.log('Websocket Client connected');
487+
console.log('PhoenixFS: Websocket Client connected');
488488
ws.binaryType = 'arraybuffer';
489489

490490
// Listen for messages from the client
491491
ws.on('message', (message) => {
492-
debugMode && console.log(`Received message ${message} of size: ${message.byteLength}, type: ${typeof message}, isArrayBuffer: ${message instanceof ArrayBuffer}, isBuffer: ${Buffer.isBuffer(message)}`);
492+
debugMode && console.log(`PhoenixFS: Received message ${message} of size: ${message.byteLength}, type: ${typeof message}, isArrayBuffer: ${message instanceof ArrayBuffer}, isBuffer: ${Buffer.isBuffer(message)}`);
493493
processWebSocketMessage(ws, message);
494494
});
495495

@@ -499,10 +499,10 @@ function CreatePhoenixFsServer(server, wssPath = "/phoenixFS") {
499499
ws.on('close', () => {
500500
if(ws.isLargeData && ws.socketGroupID && largeDataSocketMap[ws.socketGroupID] === ws){
501501
delete largeDataSocketMap[ws.socketGroupID];
502-
console.log('Websocket Client disconnected: Large data Socket');
502+
console.log('PhoenixFS: Websocket Client disconnected: Large data Socket');
503503
} else if(!ws.isLargeData && ws.socketGroupID && controlSocketMap[ws.socketGroupID] === ws){
504504
delete controlSocketMap[ws.socketGroupID];
505-
console.log('Websocket Client disconnected: control Socket');
505+
console.log('PhoenixFS: Websocket Client disconnected: control Socket');
506506
}
507507
});
508508
});

src/fslib_native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ async function _copyFileFromHandles(srcFileHandle, dstHandle, optionalName) {
341341
const writable = await dstHandle.createWritable();
342342
await srcStream.pipeTo(writable);
343343
} catch (e) {
344-
console.error(`Error while copying ${dstHandle.name}/${optionalName} : ${e}`);
344+
console.error(`PhoenixFS: Error while copying ${dstHandle.name}/${optionalName} : ${e}`);
345345
throw e;
346346
}
347347
}

src/fslib_node_ws.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function _silentlyCloseSocket(socket) {
9999
socket.autoReconnect = false;
100100
socket.close();
101101
} catch (e) {
102-
console.error(e);
102+
console.error("PhoenixFS: ", e);
103103
}
104104
}
105105

@@ -210,7 +210,7 @@ function _processEvent(metadata, bufferData) {
210210
}
211211
eventEmitter.emit(metadata.eventName, metadata.data, bufferData);
212212
} else {
213-
console.error("FS: Received stray event: ", metadata);
213+
console.error("PhoenixFS: Received stray event: ", metadata);
214214
}
215215
}
216216

@@ -259,10 +259,10 @@ async function _establishAndMaintainConnection(socketType, firstConnectCB) {
259259
}
260260
if(ws.isLargeDataWS){
261261
_execCommand(WS_COMMAND.LARGE_DATA_SOCKET_ANNOUNCE)
262-
.catch(console.error);
262+
.catch(err=> console.error("PhoenixFS: ", err));
263263
} else {
264264
_execCommand(WS_COMMAND.CONTROL_SOCKET_ANNOUNCE)
265-
.catch(console.error);
265+
.catch(err=> console.error("PhoenixFS: ", err));
266266
}
267267
_execPendingCommands();
268268
updateConnectionState();
@@ -273,7 +273,7 @@ async function _establishAndMaintainConnection(socketType, firstConnectCB) {
273273
});
274274

275275
ws.addEventListener('error', function (event) {
276-
console.error(event);
276+
console.error("PhoenixFS websocket error event: ", event);
277277
});
278278

279279
ws.addEventListener('close', function () {
@@ -285,7 +285,6 @@ async function _establishAndMaintainConnection(socketType, firstConnectCB) {
285285
ws.backoffTime = backoffTime;
286286
await _wait(backoffTime);
287287
if(ws.autoReconnect) {
288-
console.log(wssEndpoint);
289288
ws = new WebSocket(wssEndpoint);
290289
ws.backoffTime = backoffTime;
291290
ws.binaryType = 'arraybuffer';
@@ -364,13 +363,13 @@ function testNodeWsEndpoint(wsEndPoint, echoData, echoBuffer) {
364363
});
365364

366365
ws.addEventListener('error', function (event) {
367-
console.error(event);
366+
console.error("testNodeWsPort: ", event);
368367
reject(new Errors.EIO("Websocket error", wsEndPoint));
369368
ws.close();
370369
});
371370

372371
ws.addEventListener('close', function(event) {
373-
console.log('WebSocket connection closed:', event.code, event.reason);
372+
console.log('PhoenixFS: WebSocket connection closed:', event.code, event.reason);
374373
if(!opened){
375374
reject(new Errors.EIO("Socket not opened: "+ event.reason, wsEndPoint));
376375
}

src/fslib_watch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function _listenToExternalFsWatchEvents() {
7575
_setupBroadcastChannel();
7676
_channel.onmessage = async function(event) {
7777
if(virtualfs.debugMode){
78-
console.log('External fs watch event: ', event.data);
78+
console.log('PhoenixFS: External fs watch event: ', event.data);
7979
}
8080
_processFsWatchEvent(event.data, false);
8181
};

src/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,6 @@ function getTauriPlatformPath(phoenixFSPath) {
357357
phoenixFSPath = TAURI_PATH_PREFIX;
358358
}
359359
if (!phoenixFSPath.startsWith(TAURI_PATH_PREFIX)) {
360-
console.error("noop", phoenixFSPath);
361360
throw new Errors.EINVAL('Invalid Phoenix FS path- tauri path prefix expected: ' + phoenixFSPath);
362361
}
363362

src/virtualfs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ globalObject.virtualfs = {
4040
env: env
4141
};
4242

43-
console.log(`virtual fs started in debugMode:${virtualfs.debugMode} on environment: ${virtualfs.env}`);
43+
console.log(`PhoenixFS: virtual fs started in debugMode:${virtualfs.debugMode} on environment: ${virtualfs.env}`);
4444

4545
const {initFsLib} = require('./fslib');
4646
initFsLib(Filer);

test/test-watcher.browser.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ function _setupTests(testType) {
167167
watcher2 = null;
168168
}
169169
await _clean();
170+
await _waitForSomeTime(1000); // wait for 1 second to purge all delete watch events in node
170171
});
171172

172173
after(function () {
@@ -196,6 +197,8 @@ function _setupTests(testType) {
196197
it(`Should phoenix ${testType} watch for file and folder creation/deletion and change`, async function () {
197198
const watchPath = `${testPath}/watch`;
198199
await _creatDirAndValidate(watchPath);
200+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
201+
199202
watcher = await fs.watchAsync(watchPath);
200203

201204
let addedPaths = [];
@@ -242,6 +245,7 @@ function _setupTests(testType) {
242245
const watchPath = `${testPath}/a.txt`,
243246
fileInSameDirNotWatched = `${testPath}/b.txt`;
244247
await _writeTestFile(watchPath);
248+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
245249

246250
const pathChangeArray = [];
247251

@@ -273,6 +277,8 @@ function _setupTests(testType) {
273277
pathCreated = `${watchPath}/browserWrite.txt`;
274278
await _writeTestFile(pathCreated);
275279

280+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
281+
276282
watcher = await fs.watchAsync(watchPath);
277283
watcher.on(fs.WATCH_EVENTS.ADD_FILE, addToPath);
278284
watcher.on(fs.WATCH_EVENTS.UNLINK_FILE, removeFromPath);
@@ -287,6 +293,7 @@ function _setupTests(testType) {
287293
it(`Should phoenix ${testType} watch support multiple watchers concurrently on same dir`, async function () {
288294
const watchPath = `${testPath}/watch`;
289295
await _creatDirAndValidate(watchPath);
296+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
290297

291298
const pathChangeArray = [], watcher2PathChangeArray = [];
292299
let pathCreated = `${watchPath}/x`;
@@ -309,6 +316,7 @@ function _setupTests(testType) {
309316
it(`Should phoenix ${testType} watch support multiple watchers concurrently on same file`, async function () {
310317
const watchPath = `${testPath}/a.txt`;
311318
await _writeTestFile(watchPath);
319+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
312320

313321
const pathChangeArray = [], watcher2PathChangeArray = [];
314322

@@ -328,6 +336,7 @@ function _setupTests(testType) {
328336
it(`Should phoenix ${testType} watch for folder rename with nested contents`, async function () {
329337
const watchPath = `${testPath}/watch`;
330338
await _creatDirAndValidate(watchPath);
339+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
331340

332341
const pathChangeArray = [];
333342
let pathCreated = `${watchPath}/x`;
@@ -350,10 +359,13 @@ function _setupTests(testType) {
350359
const watchPath = `${testPath}/watch`;
351360
await _validate_not_exists(watchPath);
352361
await _creatDirAndValidate(watchPath);
362+
await _waitForSomeTime(500); // wait for some watcher events to trickle out maybe due to os delays
363+
353364
watcher = await fs.watchAsync(watchPath);
354365

355366
let addedPaths = [];
356367
function addToPath({path}) {
368+
console.log("received add event: ", path);
357369
addedPaths.push(path);
358370
}
359371
watcher.on(fs.WATCH_EVENTS.ADD_DIR, addToPath);
@@ -367,9 +379,7 @@ function _setupTests(testType) {
367379
addedPaths = [];
368380
pathCreated = `${watchPath}/y`;
369381
await _creatDirAndValidate(pathCreated);
370-
let waitForSomeEventsDone = false;
371-
setTimeout(()=>{waitForSomeEventsDone = true;}, 500);
372-
await waitForTrue(()=>{return waitForSomeEventsDone;},1000);
382+
await _waitForSomeTime(300);
373383
expect(addedPaths.length).to.eql(0);
374384
});
375385
}

0 commit comments

Comments
 (0)