Skip to content

Commit

Permalink
Remove redundant inodeWatching option for TestServerHos
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Mar 29, 2024
1 parent 16b4221 commit 0e970c1
Show file tree
Hide file tree
Showing 16 changed files with 308 additions and 236 deletions.
25 changes: 13 additions & 12 deletions src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export interface TestServerHostCreationParameters {
windowsStyleRoot?: string;
environmentVariables?: Map<string, string>;
runWithFallbackPolling?: boolean;
inodeWatching?: boolean;
osFlavor?: TestServerHostOsFlavor;
}

Expand Down Expand Up @@ -360,7 +359,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
importPlugin?: (root: string, moduleName: string) => Promise<ModuleImportResult>;
public storeSignatureInfo = true;
watchFile: HostWatchFile;
private inodeWatching: boolean | undefined;
private inodeWatching: boolean;
private readonly inodes?: Map<Path, number>;
watchDirectory: HostWatchDirectory;
service?: server.ProjectService;
Expand All @@ -375,7 +374,6 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
windowsStyleRoot,
environmentVariables,
runWithFallbackPolling,
inodeWatching,
osFlavor,
}: TestServerHostCreationParameters = {},
) {
Expand All @@ -393,10 +391,8 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
this.runWithFallbackPolling = !!runWithFallbackPolling;
const tscWatchFile = this.environmentVariables && this.environmentVariables.get("TSC_WATCHFILE");
const tscWatchDirectory = this.environmentVariables && this.environmentVariables.get("TSC_WATCHDIRECTORY");
if (inodeWatching) {
this.inodeWatching = true;
this.inodes = new Map();
}
this.inodeWatching = this.osFlavor !== TestServerHostOsFlavor.Windows;
if (this.inodeWatching) this.inodes = new Map();

const { watchFile, watchDirectory } = createSystemWatchFunctions({
// We dont have polling watch file
Expand All @@ -415,7 +411,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
realpath: this.realpath.bind(this),
tscWatchFile,
tscWatchDirectory,
inodeWatching: !!this.inodeWatching,
inodeWatching: this.inodeWatching,
fsWatchWithTimestamp: this.osFlavor === TestServerHostOsFlavor.MacOs,
sysLog: s => this.write(s + this.newLine),
});
Expand Down Expand Up @@ -707,15 +703,20 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
cb: FsWatchCallback,
) {
if (this.runWithFallbackPolling) throw new Error("Need to use fallback polling instead of file system native watching");
const path = this.toPath(fileOrDirectory);
// Error if the path does not exist
if (this.inodeWatching && !this.inodes?.has(path)) throw new Error();
let inode: number | undefined;
if (this.inodeWatching) {
const entry = this.getRealFileOrFolder(fileOrDirectory);
// Error if the path does not exist
if (!entry) throw new Error("Cannot watch missing file or folder");
inode = this.inodes?.get(entry.path);
if (inode === undefined) throw new Error("inode not found");
}
const result = this.watchUtils.fsWatch(
this.toNormalizedAbsolutePath(fileOrDirectory),
recursive,
{
cb,
inode: this.inodes?.get(path),
inode,
},
) as FsWatchWorkerWatcher;
result.on = noop;
Expand Down
6 changes: 3 additions & 3 deletions src/testRunner/unittests/tscWatch/watchEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand Down Expand Up @@ -631,7 +631,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand Down Expand Up @@ -665,7 +665,7 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
},
{
currentDirectory: "/user/username/projects/myproject",
inodeWatching: true,
osFlavor: TestServerHostOsFlavor.MacOs,
},
),
edits: [
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsserver/watchEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe("unittests:: tsserver:: watchEnvironment:: watching at workspaces codes
path: "/workspaces/somerepo/node_modules/@types/random-seed/index.d.ts",
content: `export function randomSeed(): string;`,
};
const host = createServerHost([config, main, randomSeed, libFile], { inodeWatching: true, osFlavor: TestServerHostOsFlavor.Linux });
const host = createServerHost([config, main, randomSeed, libFile], { osFlavor: TestServerHostOsFlavor.Linux });
const session = new TestSession(host);
openFilesForSession([main], session);
verifyGetErrRequest({ session, files: [main] });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false
Input::
//// [/a/lib/lib.d.ts]
//// [/a/lib/lib.d.ts] Inode:: 3
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
Expand All @@ -13,10 +13,10 @@ interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }

//// [/user/username/projects/myproject/main.ts]
//// [/user/username/projects/myproject/main.ts] Inode:: 8
export const x = 10;

//// [/user/username/projects/myproject/tsconfig.json]
//// [/user/username/projects/myproject/tsconfig.json] Inode:: 9
{
"files": [
"main.ts"
Expand Down Expand Up @@ -44,7 +44,7 @@ Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node



//// [/user/username/projects/myproject/main.js]
//// [/user/username/projects/myproject/main.js] Inode:: 10
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
Expand All @@ -60,9 +60,9 @@ PolledWatches::

FsWatches::
/a/lib: *new*
{}
{"inode":2}
/user/username/projects/myproject: *new*
{}
{"inode":7}

Program root files: [
"/user/username/projects/myproject/main.ts"
Expand Down Expand Up @@ -101,7 +101,7 @@ exitCode:: ExitStatus.undefined
Change:: modify file contents

Input::
//// [/user/username/projects/myproject/main.ts]
//// [/user/username/projects/myproject/main.ts] Inode:: 8
export const x = 10;export const y = 10;


Expand Down Expand Up @@ -129,7 +129,7 @@ CreatingProgramWith::



//// [/user/username/projects/myproject/main.js]
//// [/user/username/projects/myproject/main.js] Inode:: 10
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.y = exports.x = void 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
currentDirectory:: /user/username/projects/myproject useCaseSensitiveFileNames: false
Input::
//// [/a/lib/lib.d.ts]
//// [/a/lib/lib.d.ts] Inode:: 3
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
Expand All @@ -13,10 +13,10 @@ interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }

//// [/user/username/projects/myproject/main.ts]
//// [/user/username/projects/myproject/main.ts] Inode:: 8
export const x = 10;

//// [/user/username/projects/myproject/tsconfig.json]
//// [/user/username/projects/myproject/tsconfig.json] Inode:: 9
{
"files": [
"main.ts"
Expand Down Expand Up @@ -44,7 +44,7 @@ Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/node



//// [/user/username/projects/myproject/main.js]
//// [/user/username/projects/myproject/main.js] Inode:: 10
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.x = void 0;
Expand All @@ -60,11 +60,11 @@ PolledWatches::

FsWatches::
/a/lib/lib.d.ts: *new*
{}
{"inode":3}
/user/username/projects/myproject/main.ts: *new*
{}
{"inode":8}
/user/username/projects/myproject/tsconfig.json: *new*
{}
{"inode":9}

Program root files: [
"/user/username/projects/myproject/main.ts"
Expand Down Expand Up @@ -103,7 +103,7 @@ exitCode:: ExitStatus.undefined
Change:: modify file contents

Input::
//// [/user/username/projects/myproject/main.ts]
//// [/user/username/projects/myproject/main.ts] Inode:: 8
export const x = 10;export const y = 10;


Expand Down Expand Up @@ -131,7 +131,7 @@ CreatingProgramWith::



//// [/user/username/projects/myproject/main.js]
//// [/user/username/projects/myproject/main.js] Inode:: 10
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.y = exports.x = void 0;
Expand Down
Loading

0 comments on commit 0e970c1

Please sign in to comment.