Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle class setup failures preventing previously failed methods from retrying #177

Merged
merged 6 commits into from
Feb 27, 2023

Conversation

pshevche
Copy link
Member

Summary

If class setup fails, then test methods that failed in the previous execution won't be retried. In this case, we used to throw an error since we did not retry things that should be retried. This PR solves the issue by clearing the list of to-be-retried methods if class-level failure occurs. In this case, the entire class will be retried anyways, so it is safe to just clear that list. If previous run had other lifecycle errors, we track those to ensure we report successful execution of those.

@pshevche pshevche self-assigned this Feb 23, 2023
@pshevche pshevche force-pushed the pshevche/flaky-setup-prevents-method-retry branch from d904726 to 7ea416d Compare February 23, 2023 14:14
if (Files.exists(marker)) {
int counter = Integer.parseInt(new String(Files.readAllBytes(marker)));
++counter;
Files.write(marker, Integer.toString(counter).getBytes());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Files.write(marker, Integer.toString(counter).getBytes());
marker.text = counter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗ This is a Java class that we create in the build workspace to simplify creation of test classes, so this won't work.

Path marker = Paths.get("build/marker.file." + id);
try {
if (Files.exists(marker)) {
int counter = Integer.parseInt(new String(Files.readAllBytes(marker)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need the groovy-nio as test dependency for the nice Path extension methods.

Suggested change
int counter = Integer.parseInt(new String(Files.readAllBytes(marker)));
int counter = Integer.parseInt(marker.text));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, it is a plain Java class written alongside test classes.

throw new RuntimeException("fail me!");
}
} else {
Files.write(marker, "0".getBytes());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Files.write(marker, "0".getBytes());
marker.text = 0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@@ -78,6 +78,24 @@ abstract class AbstractPluginFuncTest extends Specification {
throw new java.io.UncheckedIOException(e);
}
}

public static void flakyAssertPassFailPass(String id) {
Path marker = Paths.get("build/marker.file." + id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Path marker = Paths.get("build/marker.file." + id);
Path marker = Paths.get("build/marker.file.$id");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -132,6 +150,10 @@ abstract class AbstractPluginFuncTest extends Specification {
return "acme.FlakyAssert.flakyAssert(\"${StringEscapeUtils.escapeJava(id)}\", $failures);"
}

static String flakyAssertPassFailPass(String id = "id") {
return "acme.FlakyAssert.flakyAssertPassFailPass(\"${StringEscapeUtils.escapeJava(id)}\");"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 you could use """ or as string delimiters to avoid having to use escapes for \"

@pshevche pshevche force-pushed the pshevche/flaky-setup-prevents-method-retry branch from 4ef7870 to df2e94a Compare February 27, 2023 10:09
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
Signed-off-by: Pavlo Shevchenko <pshevchenko@gradle.com>
@pshevche pshevche force-pushed the pshevche/flaky-setup-prevents-method-retry branch from df2e94a to 0ce11ad Compare February 27, 2023 10:12
@pshevche pshevche merged commit f585427 into main Feb 27, 2023
@pshevche pshevche deleted the pshevche/flaky-setup-prevents-method-retry branch February 27, 2023 13:21
@pshevche pshevche added this to the 1.5.2 milestone Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants