From eb411f1dd28bb1259677dd205e8bc34064669582 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Mon, 31 May 2010 16:23:18 +0000 Subject: [PATCH] Bug 315055 - [testing] RSEShellSubsystemTestSuite fails 3x on Windows --- .../subsystems/shells/ShellServiceTest.java | 22 ++++++++++++----- .../subsystems/shells/ShellSubSystemTest.java | 24 ++++++++++++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java index 81a1ed55307..73862d60014 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellServiceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * Anna Dushistova (MontaVista) - adapted from FileServiceTest * Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests + * Martin Oberhuber (Wind River) - [315055] ShellServiceTest fails on Windows *******************************************************************************/ package org.eclipse.rse.tests.subsystems.shells; @@ -15,6 +16,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Method; +import java.util.Arrays; import junit.framework.Test; import junit.framework.TestSuite; @@ -131,26 +133,34 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase { } public void testLaunchShell() throws Exception { - Object[] allOutput = launchShell("", "echo test", new String[] {}); + //Bug 315055: Windows needs a PATH which includes cmd.exe + //On Linux, the "echo test" also works without any PATH + //Object[] allOutput = launchShell("", "echo test", new String[] {}); + Object[] allOutput = launchShell("", "echo test", shellService.getHostEnvironment()); boolean matchFound = false; for (int i = 0; i < allOutput.length; i++) { matchFound = ((IHostOutput) allOutput[i]).getString() .equals("test"); - System.out.println(((IHostOutput) allOutput[i]).getString()); + //System.out.println(((IHostOutput) allOutput[i]).getString()); if (matchFound) break; } - assertTrue(matchFound); + assertTrue("Missing output of \"echo test\": "+Arrays.asList(allOutput), matchFound); + // now set working directory -- Linux only - allOutput = launchShell("/", "echo test", new String[] {}); + //Bug 315055: Windows needs a PATH which includes cmd.exe + //On Linux, the "echo test" also works without any PATH + //allOutput = launchShell("/", "echo test", new String[] {}); + allOutput = launchShell("/", "echo test", shellService.getHostEnvironment()); matchFound = false; for (int i = 0; i < allOutput.length; i++) { matchFound = ((IHostOutput) allOutput[i]).getString() .equals("test"); - System.out.println(((IHostOutput) allOutput[i]).getString()); + //System.out.println(((IHostOutput) allOutput[i]).getString()); if (matchFound) break; } + assertTrue("Missing output of \"echo test\": "+Arrays.asList(allOutput), matchFound); } public Object[] launchShell(String workingDirectory, String cmd, diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellSubSystemTest.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellSubSystemTest.java index 7965b0d2cdc..b36ef066082 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellSubSystemTest.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/shells/ShellSubSystemTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2010 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,10 +8,12 @@ * Contributors: * Anna Dushistova (MontaVista) - adapted from FileServiceTest * Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests + * Martin Oberhuber (Wind River) - [315055] ShellServiceTest fails on Windows *******************************************************************************/ package org.eclipse.rse.tests.subsystems.shells; import java.lang.reflect.Method; +import java.util.Arrays; import junit.framework.Test; import junit.framework.TestSuite; @@ -139,8 +141,11 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase { public void testRunCommand() throws Exception { if (shellSubSystem.canRunCommand()) { - Object[] results = shellSubSystem - .runCommand("echo test\r\nexit", null, mon); + //Bug 315055: Windows cmd invocation does not split commands on \r\n + //String cmd = "echo test\r\nexit"; //$NON-NLS-1$ + String commandSeparator = shellSubSystem.getParentRemoteCmdSubSystemConfiguration().getCommandSeparator(); + String cmd = "echo test"+commandSeparator+"exit"; //$NON-NLS-1$ + Object[] results = shellSubSystem.runCommand(cmd, null, mon); boolean matchFound = false; Object cmdObject = results[0]; @@ -159,7 +164,7 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase { break; } - assertTrue(matchFound); + assertTrue("Missing output of \"echo test\": "+Arrays.asList(result), matchFound); } } @@ -167,8 +172,15 @@ public class ShellSubSystemTest extends RSEBaseConnectionTestCase { if (shellSubSystem.canRunShell()) { IRemoteCommandShell cmd = shellSubSystem.runShell(null, mon); shellSubSystem.cancelShell(cmd, mon); - assertFalse(cmd.isActive()); - + //Bug 315055 - Race condition on Windows: + //cancelShell() is not synchronous, so we need to wait a little (max 2 sec) + int tries = 0; + while(tries <20 && cmd.isActive()) { + Thread.sleep(100); + tries++; + } + assertFalse("Shell not canceled", cmd.isActive()); + System.out.println("Shell canceled after "+tries*100+" msec."); } } }