Skip to content

Commit

Permalink
[integration-test] Add "fail fast" option
Browse files Browse the repository at this point in the history
Flowdalic committed Nov 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2ddbf73 commit afb197f
Showing 3 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -128,6 +128,8 @@ public enum DnsResolver {

public final ConnectionConfigurationBuilderApplier configurationApplier;

public final boolean failFast;

public final boolean verbose;

public final DnsResolver dnsResolver;
@@ -209,6 +211,7 @@ else if (StringUtils.isNotEmpty(builder.accountOneUsername, builder.accountOnePa
}
};

this.failFast = builder.failFast;
this.verbose = builder.verbose;

this.dnsResolver = builder.dnsResolver;
@@ -270,6 +273,8 @@ public static final class Builder {

private Set<String> testPackages;

private boolean failFast;

private boolean verbose;

private DnsResolver dnsResolver = DnsResolver.minidns;
@@ -478,6 +483,20 @@ public Builder addTestPackages(String[] testPackagesString) {
return this;
}

public Builder setFailFast(boolean failFast) {
this.failFast = failFast;
return this;
}

public Builder setFailFast(String failFastBooleanString) {
if (failFastBooleanString == null) {
return this;
}

boolean failFast = ParserUtils.parseXmlBoolean(failFastBooleanString);
return setFailFast(failFast);
}

public Builder setVerbose(boolean verbose) {
this.verbose = verbose;
return this;
@@ -601,6 +620,7 @@ public static Configuration newConfiguration(String[] testPackages)
builder.addTestPackages(properties.getProperty("testPackages"));
builder.addTestPackages(testPackages);

builder.setFailFast(properties.getProperty("failFast"));
builder.setVerbose(properties.getProperty("verbose"));

builder.setDnsResolver(properties.getProperty("dnsResolver"));
Original file line number Diff line number Diff line change
@@ -551,14 +551,20 @@ private void runTests(Set<Class<? extends AbstractSmackIntTest>> classes)
LOGGER.info(sb.toString());

for (PreparedTest test : tests) {
test.run();
boolean successful = test.run();
// Will only be not successful if a test failed and config.failFast is enabled.
if (!successful) {
break;
}
}

// Assert that all tests in the 'tests' list produced a result.
assert numberOfAvailableTests == testRunResult.getNumberOfAvailableTests();
if (!config.failFast) {
// Assert that all tests in the 'tests' list produced a result.
assert numberOfAvailableTests == testRunResult.getNumberOfAvailableTests();
}
}

private void runConcreteTest(ConcreteTest concreteTest)
private boolean runConcreteTest(ConcreteTest concreteTest)
throws InterruptedException, XMPPException, IOException, SmackException {
LOGGER.info(concreteTest + " Start");
var testStart = ZonedDateTime.now();
@@ -576,7 +582,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
LOGGER.info(concreteTest + " is not possible");
testRunResult.impossibleIntegrationTests.add(new TestNotPossible(concreteTest, testStart, testEnd,
null, (TestNotPossibleException) cause));
return;
return true;
}
Throwable nonFatalFailureReason;
// junit asserts throw an AssertionError if they fail, those should not be
@@ -593,7 +599,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
sinttestDebugger.onTestFailure(concreteTest, testEnd, nonFatalFailureReason);
}
LOGGER.log(Level.SEVERE, concreteTest + " Failed", e);
return;
return false;
}
catch (IllegalArgumentException | IllegalAccessException e) {
throw new AssertionError(e);
@@ -605,6 +611,7 @@ private void runConcreteTest(ConcreteTest concreteTest)
}
LOGGER.info(concreteTest + " Success");
testRunResult.successfulIntegrationTests.add(new SuccessfulTest(concreteTest, testStart, testEnd, null));
return true;
}

private static void verifyLowLevelTestMethod(Method method,
@@ -769,23 +776,29 @@ private PreparedTest(AbstractSmackIntTest test, List<ConcreteTest> concreteTests
afterClassMethod = getSinttestSpecialMethod(testClass, AfterClass.class);
}

public void run() throws InterruptedException, XMPPException, IOException, SmackException {
public boolean run() throws InterruptedException, XMPPException, IOException, SmackException {
try {
// Run the @BeforeClass methods (if any)
executeSinttestSpecialMethod(beforeClassMethod);

for (ConcreteTest concreteTest : concreteTests) {
TEST_UNDER_EXECUTION = concreteTest;
boolean successful;
try {
runConcreteTest(concreteTest);
successful = runConcreteTest(concreteTest);
} finally {
TEST_UNDER_EXECUTION = null;
}

if (config.failFast && !successful) {
return false;
}
}
}
finally {
executeSinttestSpecialMethod(afterClassMethod);
}
return true;
}

private void executeSinttestSpecialMethod(Method method) {
Original file line number Diff line number Diff line change
@@ -164,6 +164,10 @@
* <td>List of packages with tests</td>
* </tr>
* <tr>
* <td>failFast</td>
* <td>If <code>true</code> exit immediatly on the first failure.</td>
* </tr>
* <tr>
* <td>verbose</td>
* <td>If <code>true</code> set output to verbose</td>
* </tr>

0 comments on commit afb197f

Please sign in to comment.