Skip to content

Commit

Permalink
More baselining of host state
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Sep 7, 2022
1 parent b10b197 commit b8cd9f2
Show file tree
Hide file tree
Showing 405 changed files with 43,826 additions and 1,410 deletions.
Expand Up @@ -146,7 +146,7 @@ namespace ts.projectSystem {
logCacheAndClear(projectService.logger);

host.writeFile(imported.path, imported.content);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();
logSemanticDiagnostics(projectService, project, root);
logCacheAndClear(projectService.logger);
baselineTsserverLogs("cachingFileSystemInformation", "loads missing files from disk", projectService);
Expand Down Expand Up @@ -280,7 +280,7 @@ namespace ts.projectSystem {

// Create file cookie.ts
host.writeFile(file3.path, file3.content);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();
logCacheAndClear(projectService.logger);

projectService.openClientFile(file3.path);
Expand Down Expand Up @@ -479,15 +479,15 @@ namespace ts.projectSystem {
if (npmInstallComplete || timeoutDuringPartialInstallation) {
if (timeoutQueueLengthWhenRunningTimeouts) {
// Expected project update
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
host.runQueuedTimeoutCallbacks(); // Actual update
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
projectService.runQueuedTimeoutCallbacks(); // Actual update
}
else {
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
}
}
else {
host.checkTimeoutQueueLength(3);
projectService.checkTimeoutQueueLength(3);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/testRunner/unittests/tsserver/configFileSearch.ts
Expand Up @@ -43,7 +43,7 @@ namespace ts.projectSystem {

// Delete config file - should create inferred project and not configured project
host.deleteFile(configFile.path);
host.runQueuedTimeoutCallbacks();
service.runQueuedTimeoutCallbacks();
checkNumberOfProjects(service, { inferredProjects: 1 });
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again", service);
});
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace ts.projectSystem {

// Delete config file - should create inferred project with project root path set
host.deleteFile(configFile.path);
host.runQueuedTimeoutCallbacks();
service.runQueuedTimeoutCallbacks();
baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again 2", service);
});

Expand All @@ -98,10 +98,10 @@ namespace ts.projectSystem {
const { host, projectService } = openClientFile([file, libFile, tsconfig]);

host.deleteFile(tsconfig.path);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();

host.writeFile(tsconfig.path, tsconfig.content);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();

baselineTsserverLogs("configFileSearch", "tsconfig for the file exists", projectService);
});
Expand All @@ -110,10 +110,10 @@ namespace ts.projectSystem {
const { host, projectService } = openClientFile([file, libFile]);

host.writeFile(tsconfig.path, tsconfig.content);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();

host.deleteFile(tsconfig.path);
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();

baselineTsserverLogs("configFileSearch", "tsconfig for the file does not exist", projectService);
});
Expand Down
21 changes: 11 additions & 10 deletions src/testRunner/unittests/tsserver/configuredProjects.ts
Expand Up @@ -90,11 +90,11 @@ namespace ts.projectSystem {

// Add a tsconfig file
host.writeFile(configFile.path, configFile.content);
host.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles
projectService.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles

// remove the tsconfig file
host.deleteFile(configFile.path);
host.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects
projectService.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects

baselineTsserverLogs("configuredProjects", "add and then remove a config file in a folder with loose files", projectService);
});
Expand All @@ -110,7 +110,7 @@ namespace ts.projectSystem {

// add a new ts file
host.writeFile(commonFile2.path, commonFile2.content);
host.checkTimeoutQueueLengthAndRun(2);
projectService.checkTimeoutQueueLengthAndRun(2);
baselineTsserverLogs("configuredProjects", "add new files to a configured project without file list", projectService);
});

Expand Down Expand Up @@ -548,7 +548,7 @@ namespace ts.projectSystem {
assert.isTrue(configProject1.hasOpenRef()); // file1 and file3

host.writeFile(configFile.path, "{}");
host.runQueuedTimeoutCallbacks();
projectService.runQueuedTimeoutCallbacks();

assert.isTrue(configProject1.hasOpenRef()); // file1, file2, file3
assert.isTrue(projectService.inferredProjects[0].isOrphan());
Expand Down Expand Up @@ -577,6 +577,7 @@ namespace ts.projectSystem {
content: "let zz = 1;"
};
host.writeFile(file5.path, file5.content);
projectService.baselineHost("File5 written");
projectService.openClientFile(file5.path);

baselineTsserverLogs("configuredProjects", "Open ref of configured project when open file gets added to the project as part of configured file update", projectService);
Expand Down Expand Up @@ -1032,23 +1033,23 @@ foo();`
strict: true
}
}));
host.checkTimeoutQueueLengthAndRun(3);
projectService.checkTimeoutQueueLengthAndRun(3);

host.writeFile(bravoExtendedConfig.path, JSON.stringify({
extends: "./alpha.tsconfig.json",
compilerOptions: {
strict: false
}
}));
host.checkTimeoutQueueLengthAndRun(2);
projectService.checkTimeoutQueueLengthAndRun(2);

host.writeFile(bConfig.path, JSON.stringify({
extends: "../extended/alpha.tsconfig.json",
}));
host.checkTimeoutQueueLengthAndRun(2);
projectService.checkTimeoutQueueLengthAndRun(2);

host.writeFile(alphaExtendedConfig.path, "{}");
host.checkTimeoutQueueLengthAndRun(3);
projectService.checkTimeoutQueueLengthAndRun(3);
baselineTsserverLogs("configuredProjects", "should watch the extended configs of multiple projects", projectService);
});

Expand Down Expand Up @@ -1182,8 +1183,8 @@ foo();`
projectService.openClientFile(file1.path);

host.writeFile(file2.path, file2.content);
host.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
host.runQueuedTimeoutCallbacks(); // Actual update
projectService.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
projectService.runQueuedTimeoutCallbacks(); // Actual update

// On next file open the files file2a should be closed and not watched any more
projectService.openClientFile(file2.path);
Expand Down
Expand Up @@ -442,7 +442,7 @@ namespace ts.projectSystem {

file3.content += "export class d {}";
host.writeFile(file3.path, file3.content);
host.checkTimeoutQueueLengthAndRun(2);
session.checkTimeoutQueueLengthAndRun(2);

// Since this is first event
verifyProjectsUpdatedInBackgroundEventHandler([{
Expand All @@ -453,8 +453,8 @@ namespace ts.projectSystem {
}]);

host.writeFile(file2.path, file2.content);
host.runQueuedTimeoutCallbacks(); // For invalidation
host.runQueuedTimeoutCallbacks(); // For actual update
session.runQueuedTimeoutCallbacks(); // For invalidation
session.runQueuedTimeoutCallbacks(); // For actual update

verifyProjectsUpdatedInBackgroundEventHandler(useSlashRootAsSomeNotRootFolderInUserDirectory ? [{
eventName: server.ProjectsUpdatedInBackgroundEvent,
Expand Down
82 changes: 72 additions & 10 deletions src/testRunner/unittests/tsserver/helpers.ts
Expand Up @@ -142,7 +142,7 @@ namespace ts.projectSystem {
.replace(/getExportInfoMap: done in \d+(?:\.\d+)?/g, `getExportInfoMap: done in *`)
.replace(/collectAutoImports: \d+(?:\.\d+)?/g, `collectAutoImports: *`)
.replace(/dependencies in \d+(?:\.\d+)?/g, `dependencies in *`)
.replace(/\"exportMapKey\"\:\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`))
.replace(/\"exportMapKey\"\:\s*\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`))
)
}, host);
}
Expand Down Expand Up @@ -395,15 +395,41 @@ namespace ts.projectSystem {
private baseline<T extends protocol.Request | server.HandlerResponse>(type: "request" | "response", requestOrResult: T): T {
if (!this.logger.hasLevel(server.LogLevel.verbose)) return requestOrResult;
if (type === "request") this.logger.info(`request:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`);
this.baselineHost();
this.baselineHost(type === "request" ? "Before request" : "After request");
if (type === "response") this.logger.info(`response:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`);
return requestOrResult;
}

baselineHost() {
baselineHost(title: string) {
if (!this.logger.hasLevel(server.LogLevel.verbose)) return;
this.logger.logs.push(title);
this.testhost.diff(this.logger.logs, this.hostDiff);
this.testhost.serializeWatches(this.logger.logs);
this.hostDiff = this.testhost.snap();
this.testhost.writtenFiles.clear();
}

checkTimeoutQueueLengthAndRun(expected: number) {
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
this.testhost.checkTimeoutQueueLengthAndRun(expected);
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
}

checkTimeoutQueueLength(expected: number) {
this.baselineHost(`Checking timeout queue length: ${expected}`);
this.testhost.checkTimeoutQueueLength(expected);
}

runQueuedTimeoutCallbacks(timeoutId?: number) {
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
}

runQueuedImmediateCallbacks(checkCount?: number) {
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
this.testhost.runQueuedImmediateCallbacks(checkCount);
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
}
}

Expand Down Expand Up @@ -471,7 +497,9 @@ namespace ts.projectSystem {
}

export class TestProjectService extends server.ProjectService {
constructor(host: server.ServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
public testhost: TestFSWithWatch.TestServerHostTrackingWrittenFiles;
private hostDiff: ReturnType<TestServerHost["snap"]> | undefined;
constructor(host: TestServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean,
typingsInstaller: server.ITypingsInstaller, opts: Partial<TestProjectServiceOptions> = {}) {
super({
host,
Expand All @@ -484,14 +512,48 @@ namespace ts.projectSystem {
typesMapLocation: customTypesMap.path,
...opts
});
this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost);
this.baselineHost("Creating project service");
}

checkNumberOfProjects(count: { inferredProjects?: number, configuredProjects?: number, externalProjects?: number }) {
checkNumberOfProjects(this, count);
}

baselineHost(title: string) {
if (!this.logger.hasLevel(server.LogLevel.verbose)) return;
this.logger.logs.push(title);
this.testhost.diff(this.logger.logs, this.hostDiff);
this.testhost.serializeWatches(this.logger.logs);
this.hostDiff = this.testhost.snap();
this.testhost.writtenFiles.clear();
}

checkTimeoutQueueLengthAndRun(expected: number) {
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
this.testhost.checkTimeoutQueueLengthAndRun(expected);
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
}

checkTimeoutQueueLength(expected: number) {
this.baselineHost(`Checking timeout queue length: ${expected}`);
this.testhost.checkTimeoutQueueLength(expected);
}

runQueuedTimeoutCallbacks(timeoutId?: number) {
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
}

runQueuedImmediateCallbacks(checkCount?: number) {
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
this.testhost.runQueuedImmediateCallbacks(checkCount);
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
}
}

export function createProjectService(host: server.ServerHost, options?: Partial<TestProjectServiceOptions>) {
export function createProjectService(host: TestServerHost, options?: Partial<TestProjectServiceOptions>) {
const cancellationToken = options?.cancellationToken || server.nullCancellationToken;
const logger = options?.logger || createHasErrorMessageLogger();
const useSingleInferredProject = options?.useSingleInferredProject !== undefined ? options.useSingleInferredProject : false;
Expand Down Expand Up @@ -792,14 +854,14 @@ namespace ts.projectSystem {
Debug.assert(session.logger.logs.length);
for (let i = 0; i < files.length; i++) {
if (existingTimeouts !== undefined) {
host.checkTimeoutQueueLength(existingTimeouts + 1);
host.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
session.checkTimeoutQueueLength(existingTimeouts + 1);
session.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
}
else {
host.checkTimeoutQueueLengthAndRun(1);
session.checkTimeoutQueueLengthAndRun(1);
}
if (!skip?.[i]?.semantic) host.runQueuedImmediateCallbacks(1);
if (!skip?.[i]?.suggestion) host.runQueuedImmediateCallbacks(1);
if (!skip?.[i]?.semantic) session.runQueuedImmediateCallbacks(1);
if (!skip?.[i]?.suggestion) session.runQueuedImmediateCallbacks(1);
}
}

Expand Down

0 comments on commit b8cd9f2

Please sign in to comment.