Skip to content

Commit a88c366

Browse files
authoredSep 13, 2022
Fix test baselining for tsserver host timeouts (#50748)
1 parent 6d38487 commit a88c366

27 files changed

+467
-222
lines changed
 

‎src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace ts.projectSystem {
146146
logCacheAndClear(projectService.logger);
147147

148148
host.writeFile(imported.path, imported.content);
149-
projectService.runQueuedTimeoutCallbacks();
149+
host.runQueuedTimeoutCallbacks();
150150
logSemanticDiagnostics(projectService, project, root);
151151
logCacheAndClear(projectService.logger);
152152
baselineTsserverLogs("cachingFileSystemInformation", "loads missing files from disk", projectService);
@@ -280,7 +280,7 @@ namespace ts.projectSystem {
280280

281281
// Create file cookie.ts
282282
host.writeFile(file3.path, file3.content);
283-
projectService.runQueuedTimeoutCallbacks();
283+
host.runQueuedTimeoutCallbacks();
284284
logCacheAndClear(projectService.logger);
285285

286286
projectService.openClientFile(file3.path);
@@ -479,15 +479,15 @@ namespace ts.projectSystem {
479479
if (npmInstallComplete || timeoutDuringPartialInstallation) {
480480
if (timeoutQueueLengthWhenRunningTimeouts) {
481481
// Expected project update
482-
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
483-
projectService.runQueuedTimeoutCallbacks(); // Actual update
482+
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions
483+
host.runQueuedTimeoutCallbacks(); // Actual update
484484
}
485485
else {
486-
projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
486+
host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts);
487487
}
488488
}
489489
else {
490-
projectService.checkTimeoutQueueLength(3);
490+
host.checkTimeoutQueueLength(3);
491491
}
492492
}
493493
}

‎src/testRunner/unittests/tsserver/configFileSearch.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace ts.projectSystem {
4343

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

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

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

100100
host.deleteFile(tsconfig.path);
101-
projectService.runQueuedTimeoutCallbacks();
101+
host.runQueuedTimeoutCallbacks();
102102

103103
host.writeFile(tsconfig.path, tsconfig.content);
104-
projectService.runQueuedTimeoutCallbacks();
104+
host.runQueuedTimeoutCallbacks();
105105

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

112112
host.writeFile(tsconfig.path, tsconfig.content);
113-
projectService.runQueuedTimeoutCallbacks();
113+
host.runQueuedTimeoutCallbacks();
114114

115115
host.deleteFile(tsconfig.path);
116-
projectService.runQueuedTimeoutCallbacks();
116+
host.runQueuedTimeoutCallbacks();
117117

118118
baselineTsserverLogs("configFileSearch", "tsconfig for the file does not exist", projectService);
119119
});

‎src/testRunner/unittests/tsserver/configuredProjects.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ namespace ts.projectSystem {
9090

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

9595
// remove the tsconfig file
9696
host.deleteFile(configFile.path);
97-
projectService.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects
97+
host.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects
9898

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

111111
// add a new ts file
112112
host.writeFile(commonFile2.path, commonFile2.content);
113-
projectService.checkTimeoutQueueLengthAndRun(2);
113+
host.checkTimeoutQueueLengthAndRun(2);
114114
baselineTsserverLogs("configuredProjects", "add new files to a configured project without file list", projectService);
115115
});
116116

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

550550
host.writeFile(configFile.path, "{}");
551-
projectService.runQueuedTimeoutCallbacks();
551+
host.runQueuedTimeoutCallbacks();
552552

553553
assert.isTrue(configProject1.hasOpenRef()); // file1, file2, file3
554554
assert.isTrue(projectService.inferredProjects[0].isOrphan());
@@ -1033,23 +1033,23 @@ foo();`
10331033
strict: true
10341034
}
10351035
}));
1036-
projectService.checkTimeoutQueueLengthAndRun(3);
1036+
host.checkTimeoutQueueLengthAndRun(3);
10371037

10381038
host.writeFile(bravoExtendedConfig.path, JSON.stringify({
10391039
extends: "./alpha.tsconfig.json",
10401040
compilerOptions: {
10411041
strict: false
10421042
}
10431043
}));
1044-
projectService.checkTimeoutQueueLengthAndRun(2);
1044+
host.checkTimeoutQueueLengthAndRun(2);
10451045

10461046
host.writeFile(bConfig.path, JSON.stringify({
10471047
extends: "../extended/alpha.tsconfig.json",
10481048
}));
1049-
projectService.checkTimeoutQueueLengthAndRun(2);
1049+
host.checkTimeoutQueueLengthAndRun(2);
10501050

10511051
host.writeFile(alphaExtendedConfig.path, "{}");
1052-
projectService.checkTimeoutQueueLengthAndRun(3);
1052+
host.checkTimeoutQueueLengthAndRun(3);
10531053
baselineTsserverLogs("configuredProjects", "should watch the extended configs of multiple projects", projectService);
10541054
});
10551055

@@ -1183,8 +1183,8 @@ foo();`
11831183
projectService.openClientFile(file1.path);
11841184

11851185
host.writeFile(file2.path, file2.content);
1186-
projectService.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
1187-
projectService.runQueuedTimeoutCallbacks(); // Actual update
1186+
host.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions
1187+
host.runQueuedTimeoutCallbacks(); // Actual update
11881188

11891189
// On next file open the files file2a should be closed and not watched any more
11901190
projectService.openClientFile(file2.path);

‎src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ namespace ts.projectSystem {
442442

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

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

455455
host.writeFile(file2.path, file2.content);
456-
session.runQueuedTimeoutCallbacks(); // For invalidation
457-
session.runQueuedTimeoutCallbacks(); // For actual update
456+
host.runQueuedTimeoutCallbacks(); // For invalidation
457+
host.runQueuedTimeoutCallbacks(); // For actual update
458458

459459
verifyProjectsUpdatedInBackgroundEventHandler(useSlashRootAsSomeNotRootFolderInUserDirectory ? [{
460460
eventName: server.ProjectsUpdatedInBackgroundEvent,

‎src/testRunner/unittests/tsserver/helpers.ts

+42-51
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,41 @@ namespace ts.projectSystem {
342342
}
343343
}
344344

345+
function patchHostTimeouts(host: TestFSWithWatch.TestServerHostTrackingWrittenFiles, session: TestSession | TestProjectService) {
346+
const originalCheckTimeoutQueueLength = host.checkTimeoutQueueLength;
347+
const originalRunQueuedTimeoutCallbacks = host.runQueuedTimeoutCallbacks;
348+
const originalRunQueuedImmediateCallbacks = host.runQueuedImmediateCallbacks;
349+
350+
host.checkTimeoutQueueLengthAndRun = checkTimeoutQueueLengthAndRun;
351+
host.checkTimeoutQueueLength = checkTimeoutQueueLength;
352+
host.runQueuedTimeoutCallbacks = runQueuedTimeoutCallbacks;
353+
host.runQueuedImmediateCallbacks = runQueuedImmediateCallbacks;
354+
355+
function checkTimeoutQueueLengthAndRun(expected: number) {
356+
session.baselineHost(`Before checking timeout queue length (${expected}) and running`);
357+
originalCheckTimeoutQueueLength.call(host, expected);
358+
originalRunQueuedTimeoutCallbacks.call(host);
359+
session.baselineHost(`After checking timeout queue length (${expected}) and running`);
360+
}
361+
362+
function checkTimeoutQueueLength(expected: number) {
363+
session.baselineHost(`Checking timeout queue length: ${expected}`);
364+
originalCheckTimeoutQueueLength.call(host, expected);
365+
}
366+
367+
function runQueuedTimeoutCallbacks(timeoutId?: number) {
368+
session.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
369+
originalRunQueuedTimeoutCallbacks.call(host, timeoutId);
370+
session.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
371+
}
372+
373+
function runQueuedImmediateCallbacks(checkCount?: number) {
374+
session.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
375+
originalRunQueuedImmediateCallbacks.call(host, checkCount);
376+
session.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
377+
}
378+
}
379+
345380
export interface TestSessionOptions extends server.SessionOptions {
346381
logger: Logger;
347382
}
@@ -357,6 +392,7 @@ namespace ts.projectSystem {
357392
super(opts);
358393
this.logger = opts.logger;
359394
this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost);
395+
patchHostTimeouts(this.testhost, this);
360396
}
361397

362398
getProjectService() {
@@ -408,29 +444,6 @@ namespace ts.projectSystem {
408444
this.hostDiff = this.testhost.snap();
409445
this.testhost.writtenFiles.clear();
410446
}
411-
412-
checkTimeoutQueueLengthAndRun(expected: number) {
413-
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
414-
this.testhost.checkTimeoutQueueLengthAndRun(expected);
415-
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
416-
}
417-
418-
checkTimeoutQueueLength(expected: number) {
419-
this.baselineHost(`Checking timeout queue length: ${expected}`);
420-
this.testhost.checkTimeoutQueueLength(expected);
421-
}
422-
423-
runQueuedTimeoutCallbacks(timeoutId?: number) {
424-
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
425-
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
426-
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
427-
}
428-
429-
runQueuedImmediateCallbacks(checkCount?: number) {
430-
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
431-
this.testhost.runQueuedImmediateCallbacks(checkCount);
432-
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
433-
}
434447
}
435448

436449
export function createSession(host: server.ServerHost, opts: Partial<TestSessionOptions> = {}) {
@@ -513,6 +526,7 @@ namespace ts.projectSystem {
513526
...opts
514527
});
515528
this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost);
529+
patchHostTimeouts(this.testhost, this);
516530
this.baselineHost("Creating project service");
517531
}
518532

@@ -528,29 +542,6 @@ namespace ts.projectSystem {
528542
this.hostDiff = this.testhost.snap();
529543
this.testhost.writtenFiles.clear();
530544
}
531-
532-
checkTimeoutQueueLengthAndRun(expected: number) {
533-
this.baselineHost(`Before checking timeout queue length (${expected}) and running`);
534-
this.testhost.checkTimeoutQueueLengthAndRun(expected);
535-
this.baselineHost(`After checking timeout queue length (${expected}) and running`);
536-
}
537-
538-
checkTimeoutQueueLength(expected: number) {
539-
this.baselineHost(`Checking timeout queue length: ${expected}`);
540-
this.testhost.checkTimeoutQueueLength(expected);
541-
}
542-
543-
runQueuedTimeoutCallbacks(timeoutId?: number) {
544-
this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
545-
this.testhost.runQueuedTimeoutCallbacks(timeoutId);
546-
this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`);
547-
}
548-
549-
runQueuedImmediateCallbacks(checkCount?: number) {
550-
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
551-
this.testhost.runQueuedImmediateCallbacks(checkCount);
552-
this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`);
553-
}
554545
}
555546

556547
export function createProjectService(host: TestServerHost, options?: Partial<TestProjectServiceOptions>) {
@@ -854,14 +845,14 @@ namespace ts.projectSystem {
854845
Debug.assert(session.logger.logs.length);
855846
for (let i = 0; i < files.length; i++) {
856847
if (existingTimeouts !== undefined) {
857-
session.checkTimeoutQueueLength(existingTimeouts + 1);
858-
session.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
848+
host.checkTimeoutQueueLength(existingTimeouts + 1);
849+
host.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1);
859850
}
860851
else {
861-
session.checkTimeoutQueueLengthAndRun(1);
852+
host.checkTimeoutQueueLengthAndRun(1);
862853
}
863-
if (!skip?.[i]?.semantic) session.runQueuedImmediateCallbacks(1);
864-
if (!skip?.[i]?.suggestion) session.runQueuedImmediateCallbacks(1);
854+
if (!skip?.[i]?.semantic) host.runQueuedImmediateCallbacks(1);
855+
if (!skip?.[i]?.suggestion) host.runQueuedImmediateCallbacks(1);
865856
}
866857
}
867858

0 commit comments

Comments
 (0)
Please sign in to comment.