mirror of
https://github.com/frohoff/ysoserial.git
synced 2026-09-21 22:50:46 +08:00
retry on failure for flaky gadgets/tests
This commit is contained in:
@@ -46,7 +46,7 @@ import ysoserial.payloads.util.Reflections;
|
|||||||
* $ cat /tmp/upload_3805815b_2d50_4e00_9dae_a854d5a0e614_479431761.tmp
|
* $ cat /tmp/upload_3805815b_2d50_4e00_9dae_a854d5a0e614_479431761.tmp
|
||||||
* blue lobster
|
* blue lobster
|
||||||
*/
|
*/
|
||||||
@PayloadTest(harness = "ysoserial.payloads.FileUploadTest")
|
@PayloadTest(harness = "ysoserial.payloads.FileUploadTest", flaky="possible race condition")
|
||||||
@Dependencies({"org.apache.wicket:wicket-util:6.23.0", "org.slf4j:slf4j-api:1.6.4"})
|
@Dependencies({"org.apache.wicket:wicket-util:6.23.0", "org.slf4j:slf4j-api:1.6.4"})
|
||||||
@Authors({ Authors.JACOBAINES })
|
@Authors({ Authors.JACOBAINES })
|
||||||
public class Wicket1 implements ReleaseableObjectPayload<DiskFileItem> {
|
public class Wicket1 implements ReleaseableObjectPayload<DiskFileItem> {
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface PayloadTest {
|
public @interface PayloadTest {
|
||||||
|
|
||||||
String skip() default "";
|
String skip() default "";
|
||||||
|
|
||||||
String precondition() default "";
|
String precondition() default "";
|
||||||
|
|
||||||
String harness() default "";
|
String harness() default "";
|
||||||
|
|
||||||
|
String flaky() default "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,13 +18,8 @@ import org.junit.runner.RunWith;
|
|||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
import ysoserial.CustomDeserializer;
|
import ysoserial.*;
|
||||||
import ysoserial.CustomPayloadArgs;
|
|
||||||
import ysoserial.CustomTest;
|
|
||||||
import ysoserial.Deserializer;
|
|
||||||
import ysoserial.Serializer;
|
|
||||||
import ysoserial.util.Throwables;
|
import ysoserial.util.Throwables;
|
||||||
import ysoserial.WrappedTest;
|
|
||||||
import ysoserial.payloads.TestHarnessTest.ExecMockPayload;
|
import ysoserial.payloads.TestHarnessTest.ExecMockPayload;
|
||||||
import ysoserial.payloads.TestHarnessTest.NoopMockPayload;
|
import ysoserial.payloads.TestHarnessTest.NoopMockPayload;
|
||||||
import ysoserial.payloads.annotation.Dependencies;
|
import ysoserial.payloads.annotation.Dependencies;
|
||||||
@@ -74,6 +69,7 @@ public class PayloadsTest {
|
|||||||
|
|
||||||
PayloadTest t = payloadClass.getAnnotation(PayloadTest.class);
|
PayloadTest t = payloadClass.getAnnotation(PayloadTest.class);
|
||||||
|
|
||||||
|
int tries = 1;
|
||||||
if ( t != null ) {
|
if ( t != null ) {
|
||||||
if ( !t.skip().isEmpty() ) {
|
if ( !t.skip().isEmpty() ) {
|
||||||
Assume.assumeTrue(t.skip(), false);
|
Assume.assumeTrue(t.skip(), false);
|
||||||
@@ -82,6 +78,10 @@ public class PayloadsTest {
|
|||||||
if ( !t.precondition().isEmpty() ) {
|
if ( !t.precondition().isEmpty() ) {
|
||||||
Assume.assumeTrue("Precondition: " + t.precondition(), checkPrecondition(payloadClass, t.precondition()));
|
Assume.assumeTrue("Precondition: " + t.precondition(), checkPrecondition(payloadClass, t.precondition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! t.flaky().isEmpty()) {
|
||||||
|
tries = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] deps = buildDeps(payloadClass);
|
String[] deps = buildDeps(payloadClass);
|
||||||
@@ -114,11 +114,22 @@ public class PayloadsTest {
|
|||||||
callable = ( (WrappedTest) testHarness ).createCallable(callable);
|
callable = ( (WrappedTest) testHarness ).createCallable(callable);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( testHarness instanceof CustomTest ) {
|
if (testHarness instanceof CustomTest) {
|
||||||
( (CustomTest) testHarness ).run(callable);
|
// if marked as flaky try up to 5 times
|
||||||
return;
|
Exception ex = new Exception();
|
||||||
|
for (int i = 0; i < tries; i++) {
|
||||||
|
try {
|
||||||
|
((CustomTest) testHarness).run(callable);
|
||||||
|
ex = null;
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
ex = e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (ex != null) throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user