ML - Fixed a failing test (#13080)

* Fixed a failing test
This commit is contained in:
Leila Lali
2020-10-27 06:42:33 -07:00
committed by GitHub
parent eec6f64d62
commit f97ae9e570
2 changed files with 20 additions and 11 deletions

View File

@@ -17,10 +17,6 @@ export class ProcessService {
const scriptExecution = childProcess.spawn(exeFilePath, args); const scriptExecution = childProcess.spawn(exeFilePath, args);
let timer: NodeJS.Timeout; let timer: NodeJS.Timeout;
let output: string = ''; let output: string = '';
scripts.forEach(script => {
scriptExecution.stdin.write(`${script}\n`);
});
scriptExecution.stdin.end();
// Add listeners to print stdout and stderr if an output channel was provided // Add listeners to print stdout and stderr if an output channel was provided
@@ -55,6 +51,11 @@ export class ProcessService {
console.log(error); console.log(error);
} }
}, this.timeout); }, this.timeout);
scripts.forEach(script => {
scriptExecution.stdin.write(`${script}\n`);
});
scriptExecution.stdin.end();
}); });
} }

View File

@@ -27,15 +27,23 @@ function createContext(): TestContext {
}; };
} }
function execFolderListCommand(context: TestContext, service : ProcessService): Promise<string> { function execFolderListCommand(context: TestContext, service: ProcessService): Promise<string> {
if (utils.isWindows()) { if (utils.isWindows()) {
return service.execScripts('cmd', ['dir', '.'], [], context.outputChannel); return service.execScripts('cmd', ['dir', '.'], [], context.outputChannel);
} else { } else {
return service.execScripts('/bin/sh', ['-c', 'ls'], [], context.outputChannel); return service.execScripts('/bin/sh', ['ls'], [], context.outputChannel);
} }
} }
function execFolderListBufferedCommand(context: TestContext, service : ProcessService): Promise<string> { function execGetCharacterCommand(context: TestContext, service: ProcessService): Promise<string> {
if (utils.isWindows()) {
return service.execScripts('cmd', ['set', '/p', 'asd="Hit enter"'], [], context.outputChannel);
} else {
return service.execScripts('/bin/sh', ['read'], [], context.outputChannel);
}
}
function execFolderListBufferedCommand(context: TestContext, service: ProcessService): Promise<string> {
if (utils.isWindows()) { if (utils.isWindows()) {
return service.executeBufferedCommand('dir', context.outputChannel); return service.executeBufferedCommand('dir', context.outputChannel);
} else { } else {
@@ -44,20 +52,20 @@ function execFolderListBufferedCommand(context: TestContext, service : ProcessSe
} }
describe('Process Service', () => { describe('Process Service', () => {
it('Executing a valid script should return successfully', async function (): Promise<void> { it('execScripts should return successfully', async function (): Promise<void> {
const context = createContext(); const context = createContext();
let service = new ProcessService(); let service = new ProcessService();
await should(execFolderListCommand(context, service)).resolved(); await should(execFolderListCommand(context, service)).resolved();
}); });
it('execFolderListCommand should reject if command time out @UNSTABLE@', async function (): Promise<void> { it('execScripts should reject if command times out', async function (): Promise<void> {
const context = createContext(); const context = createContext();
let service = new ProcessService(); let service = new ProcessService();
service.timeout = 10; service.timeout = 10;
await should(execFolderListCommand(context, service)).rejected(); await should(execGetCharacterCommand(context, service)).rejected();
}); });
it('executeBufferedCommand should resolve give valid script', async function (): Promise<void> { it('execScripts should resolve give valid script', async function (): Promise<void> {
const context = createContext(); const context = createContext();
let service = new ProcessService(); let service = new ProcessService();
service.timeout = 2000; service.timeout = 2000;