Skip to content

Commit

Permalink
ARTEMIS-3409: skip tests if preconditions cant be satisfied
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmellr authored and clebertsuconic committed Aug 3, 2021
1 parent 1883801 commit 6b8fdcb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
Expand Up @@ -90,19 +90,29 @@ private enum OS {
osUsed = osTmp;
}

public static void failIfNotSudo() {
Assume.assumeTrue("non supported OS", osUsed != OS.NON_SUPORTED);
if (!canSudo()) {
public static void skipIfNotSudo() {
skipIfNotSupportedOS();

boolean canSudo = canSudo();
if (!canSudo) {
StringWriter writer = new StringWriter();
PrintWriter out = new PrintWriter(writer);
out.println("Add the following at the end of your /etc/sudoers (use the visudo command)");
out.println("In order to run this test you must be able to sudo ifconfig.");
out.println("E.g add the following at the end of your /etc/sudoers (use the visudo command)");
out.println("# ------------------------------------------------------- ");
out.println(user + " ALL = NOPASSWD: /sbin/ifconfig");
out.println("# ------------------------------------------------------- ");
Assert.fail(writer.toString());

System.out.println(writer.toString());

Assume.assumeTrue("Not able to sudo ifconfig", canSudo);
}
}

public static void skipIfNotSupportedOS() {
Assume.assumeTrue("non supported OS", osUsed != OS.NON_SUPORTED);
}

public static void cleanup() {
nextDevice.set(0);

Expand Down
Expand Up @@ -55,8 +55,8 @@
/**
* This test will simulate a failure where the network card is gone.
* On that case the server should fail (as in stop) and not hung.
* If you don't have sudoer access to ifutil, this test will fail.
* You should add sudoer on your environment. otherwise you will have to ignore failures here.
* If you don't have sudoer access to ifutil, this test will skip.
* You should add sudoer on your environment to run the test.
*/
public class NetworkFailureFailoverTest extends FailoverTestBase {

Expand All @@ -65,7 +65,7 @@ public class NetworkFailureFailoverTest extends FailoverTestBase {

@BeforeClass
public static void start() {
NetUtil.failIfNotSudo();
NetUtil.skipIfNotSudo();
}

// 192.0.2.0 is reserved for documentation (and testing on this case).
Expand Down
Expand Up @@ -143,12 +143,17 @@ private static ActiveMQServerControl getServerControl(String uri,

@BeforeClass
public static void beforeClassMethod() throws Exception {
NetUtil.skipIfNotSupportedOS();

if (USE_ETC_HOSTS) {
if (!ETC_HOSTS.canWrite()) {
System.out.println("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS);
}
Assume.assumeTrue("If you want to run this test, you must do 'sudo chmod 666 " + ETC_HOSTS + "'", ETC_HOSTS.canWrite());
} else {
NetUtil.skipIfNotSudo();
}

serverLocation = getServerLocation(SERVER_NAME_0);
// Before anything we must copy the jave security and change what we need for no cache
// this will be used to spawn new tests
Expand All @@ -163,7 +168,6 @@ public static void beforeClassMethod() throws Exception {
Files.copy(ETC_HOSTS.toPath(), ETC_BACKUP.toPath(), StandardCopyOption.COPY_ATTRIBUTES);
}
}
NetUtil.failIfNotSudo();
}

private static File getETCBackup() {
Expand Down

0 comments on commit 6b8fdcb

Please sign in to comment.