-
Notifications
You must be signed in to change notification settings - Fork 1.2k
switch to using temp file for test_ids #24054
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
Changes from all commits
0daa2ee
21cff74
9afc101
9a908e2
a63d23f
9765799
6df8d26
e6aa596
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import sys | ||
|
||
# Ignore the contents of this folder for Python 2 tests. | ||
if sys.version_info[0] < 3: | ||
collect_ignore_glob = ["*.py"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
import * as net from 'net'; | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import * as os from 'os'; | ||
import * as crypto from 'crypto'; | ||
import { CancellationToken, Position, TestController, TestItem, Uri, Range, Disposable } from 'vscode'; | ||
import { Message } from 'vscode-jsonrpc'; | ||
import { traceError, traceInfo, traceLog, traceVerbose } from '../../../logging'; | ||
|
@@ -20,6 +22,7 @@ import { | |
} from './types'; | ||
import { Deferred, createDeferred } from '../../../common/utils/async'; | ||
import { createNamedPipeServer, generateRandomPipeName } from '../../../common/pipes/namedPipes'; | ||
import { EXTENSION_ROOT_DIR } from '../../../constants'; | ||
|
||
export function fixLogLines(content: string): string { | ||
const lines = content.split(/\r?\n/g); | ||
|
@@ -193,6 +196,36 @@ interface ExecutionResultMessage extends Message { | |
params: ExecutionTestPayload | EOTTestPayload; | ||
} | ||
|
||
/** | ||
* Writes an array of test IDs to a temporary file. | ||
* | ||
* @param testIds - The array of test IDs to write. | ||
* @returns A promise that resolves to the file name of the temporary file. | ||
*/ | ||
export async function writeTestIdsFile(testIds: string[]): Promise<string> { | ||
// temp file name in format of test-ids-<randomSuffix>.txt | ||
const randomSuffix = crypto.randomBytes(10).toString('hex'); | ||
const tempName = `test-ids-${randomSuffix}.txt`; | ||
// create temp file | ||
let tempFileName: string; | ||
try { | ||
traceLog('Attempting to use temp directory for test ids file, file name:', tempName); | ||
tempFileName = path.join(os.tmpdir(), tempName); | ||
} catch (error) { | ||
// Handle the error when accessing the temp directory | ||
traceError('Error accessing temp directory:', error, ' Attempt to use extension root dir instead'); | ||
// Make new temp directory in extension root dir | ||
const tempDir = path.join(EXTENSION_ROOT_DIR, '.temp'); | ||
await fs.promises.mkdir(tempDir, { recursive: true }); | ||
tempFileName = path.join(EXTENSION_ROOT_DIR, '.temp', tempName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to explicitly create the directory or does it automatically create on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideas on how to test this manually or with a test case? Seems like I can't mock tmpdir to include it in a test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will show you a trick for a future PR |
||
traceLog('New temp file:', tempFileName); | ||
} | ||
// write test ids to file | ||
await fs.promises.writeFile(tempFileName, testIds.join('\n')); | ||
// return file name | ||
return tempFileName; | ||
} | ||
|
||
export async function startRunResultNamedPipe( | ||
dataReceivedCallback: (payload: ExecutionTestPayload | EOTTestPayload) => void, | ||
deferredTillServerClose: Deferred<void>, | ||
|
Uh oh!
There was an error while loading. Please reload this page.