Skip to content

Instead of using current time, use predefined time for modification to ensure we can detect changes correctly and arent timing dependent #22526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/harness/virtualFileSystemWithWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,14 @@ interface Array<T> {}`
DynamicPolling = "RecursiveDirectoryUsingDynamicPriorityPolling"
}

const timeIncrements = 1000;
export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost, ModuleResolutionHost {
args: string[] = [];

private readonly output: string[] = [];

private fs: Map<FSEntry> = createMap<FSEntry>();
private time = timeIncrements;
getCanonicalFileName: (s: string) => string;
private toPath: (f: string) => Path;
private timeoutCallbacks = new Callbacks();
Expand Down Expand Up @@ -355,6 +357,11 @@ interface Array<T> {}`
return s;
}

private now() {
this.time += timeIncrements;
return new Date(this.time);
}

reloadFS(fileOrFolderList: ReadonlyArray<FileOrFolder>, options?: Partial<ReloadWatchInvokeOptions>) {
const mapNewLeaves = createMap<true>();
const isNewFs = this.fs.size === 0;
Expand All @@ -381,8 +388,8 @@ interface Array<T> {}`
}
else {
currentEntry.content = fileOrDirectory.content;
currentEntry.modifiedTime = new Date();
this.fs.get(getDirectoryPath(currentEntry.path)).modifiedTime = new Date();
currentEntry.modifiedTime = this.now();
this.fs.get(getDirectoryPath(currentEntry.path)).modifiedTime = this.now();
if (options && options.invokeDirectoryWatcherInsteadOfFileChanged) {
this.invokeDirectoryWatcher(getDirectoryPath(currentEntry.fullPath), currentEntry.fullPath);
}
Expand All @@ -406,7 +413,7 @@ interface Array<T> {}`
}
else {
// Folder update: Nothing to do.
currentEntry.modifiedTime = new Date();
currentEntry.modifiedTime = this.now();
}
}
}
Expand Down Expand Up @@ -505,7 +512,7 @@ interface Array<T> {}`

private addFileOrFolderInFolder(folder: Folder, fileOrDirectory: File | Folder | SymLink, ignoreWatch?: boolean) {
insertSorted(folder.entries, fileOrDirectory, (a, b) => compareStringsCaseSensitive(getBaseFileName(a.path), getBaseFileName(b.path)));
folder.modifiedTime = new Date();
folder.modifiedTime = this.now();
this.fs.set(fileOrDirectory.path, fileOrDirectory);

if (ignoreWatch) {
Expand All @@ -520,7 +527,7 @@ interface Array<T> {}`
const baseFolder = this.fs.get(basePath) as Folder;
if (basePath !== fileOrDirectory.path) {
Debug.assert(!!baseFolder);
baseFolder.modifiedTime = new Date();
baseFolder.modifiedTime = this.now();
filterMutate(baseFolder.entries, entry => entry !== fileOrDirectory);
}
this.fs.delete(fileOrDirectory.path);
Expand Down Expand Up @@ -587,7 +594,7 @@ interface Array<T> {}`
return {
path: this.toPath(fullPath),
fullPath,
modifiedTime: new Date()
modifiedTime: this.now()
};
}

Expand Down