From 83f065012f5805c115a61d5146e0a3a5bc51bc1e Mon Sep 17 00:00:00 2001 From: Illia Bershadskyi Date: Tue, 22 Nov 2016 21:15:32 +0100 Subject: [PATCH] Added reRunsCount parameter to re-run failed tests --- .../groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy | 3 +++ .../groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy | 1 + .../groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy | 9 +++++++++ 3 files changed, 13 insertions(+) mode change 100644 => 100755 src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy mode change 100644 => 100755 src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy mode change 100644 => 100755 src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy diff --git a/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy b/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy old mode 100644 new mode 100755 index fc74a45..9ad3897 --- a/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy +++ b/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy @@ -56,4 +56,7 @@ class SpoonExtension { /** Grants all permisions for Android M >= devices */ boolean grantAllPermissions + + /** Tests re-run count to re-run tests in case of failure in order to eliminate flakiness */ + int reRunsCount = 1; } diff --git a/src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy b/src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy old mode 100644 new mode 100755 index 9a90a4f..9ec48dd --- a/src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy +++ b/src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy @@ -126,6 +126,7 @@ class SpoonPlugin implements Plugin { codeCoverage = config.codeCoverage shard = config.shard grantAllPermissions = config.grantAllPermissions + reRunsCount = config.reRunsCount if (config.adbTimeout != -1) { // Timeout is defined in seconds in the config. adbTimeout = config.adbTimeout * 1000 diff --git a/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy b/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy old mode 100644 new mode 100755 index ecd003d..f7bb686 --- a/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy +++ b/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy @@ -101,6 +101,9 @@ class SpoonRunTask extends DefaultTask implements VerificationTask { /** Grants all permisions for Android M >= devices */ boolean grantAllPermissions + /** Tests re-run count to re-run tests in case of failure in order to eliminate flakiness */ + int reRunsCount; + @TaskAction void runSpoon() { LOG.info("Run instrumentation tests $instrumentationApk for app $applicationApk") @@ -189,6 +192,12 @@ class SpoonRunTask extends DefaultTask implements VerificationTask { } boolean success = runBuilder.build().run() + int runsCount = 1; + while(!success && reRunsCount > runsCount) { + LOG.info("Tests failed. Trying to re-run now") + success = runBuilder.build().run() + runsCount++ + } if (!success && !ignoreFailures) { throw new GradleException("Tests failed! See ${output}/index.html")