From f97ae9e570691283220625b8eded665bb609c20b Mon Sep 17 00:00:00 2001 From: Leila Lali Date: Tue, 27 Oct 2020 06:42:33 -0700 Subject: [PATCH] ML - Fixed a failing test (#13080) * Fixed a failing test --- .../src/common/processService.ts | 9 ++++---- .../src/test/common/processService.test.ts | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/extensions/machine-learning/src/common/processService.ts b/extensions/machine-learning/src/common/processService.ts index 2a66ef0d18..82136a0f98 100644 --- a/extensions/machine-learning/src/common/processService.ts +++ b/extensions/machine-learning/src/common/processService.ts @@ -17,10 +17,6 @@ export class ProcessService { const scriptExecution = childProcess.spawn(exeFilePath, args); let timer: NodeJS.Timeout; 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 @@ -55,6 +51,11 @@ export class ProcessService { console.log(error); } }, this.timeout); + + scripts.forEach(script => { + scriptExecution.stdin.write(`${script}\n`); + }); + scriptExecution.stdin.end(); }); } diff --git a/extensions/machine-learning/src/test/common/processService.test.ts b/extensions/machine-learning/src/test/common/processService.test.ts index 87731b846f..f5a3eac111 100644 --- a/extensions/machine-learning/src/test/common/processService.test.ts +++ b/extensions/machine-learning/src/test/common/processService.test.ts @@ -27,15 +27,23 @@ function createContext(): TestContext { }; } -function execFolderListCommand(context: TestContext, service : ProcessService): Promise { +function execFolderListCommand(context: TestContext, service: ProcessService): Promise { if (utils.isWindows()) { return service.execScripts('cmd', ['dir', '.'], [], context.outputChannel); } 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 { +function execGetCharacterCommand(context: TestContext, service: ProcessService): Promise { + 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 { if (utils.isWindows()) { return service.executeBufferedCommand('dir', context.outputChannel); } else { @@ -44,20 +52,20 @@ function execFolderListBufferedCommand(context: TestContext, service : ProcessSe } describe('Process Service', () => { - it('Executing a valid script should return successfully', async function (): Promise { + it('execScripts should return successfully', async function (): Promise { const context = createContext(); let service = new ProcessService(); await should(execFolderListCommand(context, service)).resolved(); }); - it('execFolderListCommand should reject if command time out @UNSTABLE@', async function (): Promise { + it('execScripts should reject if command times out', async function (): Promise { const context = createContext(); let service = new ProcessService(); 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 { + it('execScripts should resolve give valid script', async function (): Promise { const context = createContext(); let service = new ProcessService(); service.timeout = 2000;