Skip to content

Commit 064e967

Browse files
committed
feature: show initialize message only when needed
1 parent 2dc33f9 commit 064e967

File tree

2 files changed

+92
-12
lines changed

2 files changed

+92
-12
lines changed

packages/test-coordinator/src/parts/RunTestsWithCallback/RunTestsWithCallback.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Id from '../Id/Id.ts'
99
import * as MemoryLeakFinder from '../MemoryLeakFinder/MemoryLeakFinder.ts'
1010
import * as MemoryLeakResultsPath from '../MemoryLeakResultsPath/MemoryLeakResultsPath.ts'
1111
import * as PrepareTestsOrAttach from '../PrepareTestsOrAttach/PrepareTestsOrAttach.ts'
12+
import * as ShouldShowInitializingMessage from '../ShouldShowInitializingMessage/ShouldShowInitializingMessage.ts'
1213
import * as TestWorkerEventType from '../TestWorkerEventType/TestWorkerEventType.ts'
1314
import * as TestWorkerRunTests from '../TestWorkerRunTests/TestWorkerRunTests.ts'
1415
import * as TestWorkerSetupTest from '../TestWorkerSetupTest/TestWorkerSetupTest.ts'
@@ -225,20 +226,26 @@ export const runTestsWithCallback = async ({
225226
}
226227
const initialStart = Time.now()
227228
const first = formattedPaths[0]
228-
await callback(TestWorkerEventType.HandleInitializing)
229+
const showInitializingMessage = await ShouldShowInitializingMessage.shouldShowInitializingMessage({
230+
arch,
231+
commit,
232+
ide,
233+
insidersCommit,
234+
platform,
235+
vscodePath,
236+
vscodeVersion,
237+
})
229238

230239
const context = {
231240
runs,
232241
}
233242

234-
const intializeEnd = performance.now()
235-
const intializeTime = intializeEnd - initialStart
236-
237-
await callback(TestWorkerEventType.HandleInitialized, intializeTime)
238-
239-
const testStart = performance.now()
240-
await callback(TestWorkerEventType.TestsStarting, total)
241-
await callback(TestWorkerEventType.TestRunning, first.absolutePath, first.relativeDirname, first.dirent, /* isFirst */ true)
243+
let testStart = 0
244+
if (!showInitializingMessage) {
245+
testStart = performance.now()
246+
await callback(TestWorkerEventType.TestsStarting, total)
247+
await callback(TestWorkerEventType.TestRunning, first.absolutePath, first.relativeDirname, first.dirent, true)
248+
}
242249

243250
let workers = {
244251
functionTrackerRpc: emptyRpc,
@@ -247,6 +254,7 @@ export const runTestsWithCallback = async ({
247254
testWorkerRpc: emptyRpc,
248255
videoRpc: emptyRpc,
249256
}
257+
let hasHandledInitializing = false
250258

251259
for (let i = 0; i < formattedPaths.length; i++) {
252260
const formattedPath = formattedPaths[i]
@@ -256,6 +264,10 @@ export const runTestsWithCallback = async ({
256264
const needsSetup = i === 0 || restartBetween
257265

258266
if (needsSetup) {
267+
const initializeStart = Time.now()
268+
if (showInitializingMessage && !hasHandledInitializing) {
269+
await callback(TestWorkerEventType.HandleInitializing)
270+
}
259271
await disposeWorkers(workers)
260272
PrepareTestsOrAttach.state.promise = undefined
261273
const { functionTrackerRpc, initializationWorkerRpc, memoryRpc, testWorkerRpc, videoRpc } =
@@ -295,6 +307,11 @@ export const runTestsWithCallback = async ({
295307
vscodePath,
296308
vscodeVersion,
297309
})
310+
if (showInitializingMessage && !hasHandledInitializing) {
311+
const intializeTime = performance.now() - initializeStart
312+
await callback(TestWorkerEventType.HandleInitialized, intializeTime)
313+
hasHandledInitializing = true
314+
}
298315
workers = {
299316
functionTrackerRpc: functionTrackerRpc || emptyRpc,
300317
initializationWorkerRpc: initializationWorkerRpc || emptyRpc,
@@ -307,11 +324,16 @@ export const runTestsWithCallback = async ({
307324

308325
const { memoryRpc, testWorkerRpc, videoRpc } = workers
309326

310-
let wasOriginallySkipped = false
311-
if (i !== 0) {
312-
await callback(TestWorkerEventType.TestRunning, absolutePath, relativeDirname, dirent, /* isFirst */ true)
327+
if (i === 0 && showInitializingMessage) {
328+
testStart = performance.now()
329+
await callback(TestWorkerEventType.TestsStarting, total)
330+
await callback(TestWorkerEventType.TestRunning, absolutePath, relativeDirname, dirent, true)
331+
} else if (i !== 0) {
332+
await callback(TestWorkerEventType.TestRunning, absolutePath, relativeDirname, dirent, false)
313333
}
314334

335+
let wasOriginallySkipped = false
336+
315337
try {
316338
const start = i === 0 ? initialStart : Time.now()
317339
const testResult = await TestWorkerSetupTest.testWorkerSetupTest(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { existsSync } from 'node:fs'
2+
import { readFile } from 'node:fs/promises'
3+
import { join } from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
import * as Ide from '../Ide/Ide.ts'
6+
import * as Root from '../Root/Root.ts'
7+
8+
export interface ShouldShowInitializingMessageOptions {
9+
readonly arch: string
10+
readonly commit: string
11+
readonly ide: string
12+
readonly insidersCommit: string
13+
readonly platform: string
14+
readonly vscodePath: string
15+
readonly vscodeVersion: string
16+
}
17+
18+
const getCacheFilePath = (cacheKey: string, platform: string, arch: string): string => {
19+
return join(Root.root, '.vscode-runtime-paths', `${cacheKey}-${platform}-${arch}.json`)
20+
}
21+
22+
const isRuntimeCached = async (cacheKey: string, platform: string, arch: string): Promise<boolean> => {
23+
if (!cacheKey) {
24+
return false
25+
}
26+
const cacheFilePath = getCacheFilePath(cacheKey, platform, arch)
27+
if (!existsSync(cacheFilePath)) {
28+
return false
29+
}
30+
try {
31+
const cacheContent = await readFile(cacheFilePath, 'utf8')
32+
const cache = JSON.parse(cacheContent)
33+
const pathUri = cache.uri || cache.path
34+
if (typeof pathUri !== 'string' || pathUri === '') {
35+
return false
36+
}
37+
const binaryPath = pathUri.startsWith('file://') ? fileURLToPath(pathUri) : pathUri
38+
return existsSync(binaryPath)
39+
} catch {
40+
return false
41+
}
42+
}
43+
44+
export const shouldShowInitializingMessage = async (options: ShouldShowInitializingMessageOptions): Promise<boolean> => {
45+
const { arch, commit, ide, insidersCommit, platform, vscodePath, vscodeVersion } = options
46+
if (ide !== Ide.VsCode) {
47+
return false
48+
}
49+
if (vscodePath || process.env.VSCODE_PATH) {
50+
return false
51+
}
52+
if (commit) {
53+
return false
54+
}
55+
const cacheKey = insidersCommit || vscodeVersion
56+
const isDownloaded = await isRuntimeCached(cacheKey, platform, arch)
57+
return !isDownloaded
58+
}

0 commit comments

Comments
 (0)