Skip to content

Commit

Permalink
Implement flow on test faliure
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephBK committed Jul 16, 2019
1 parent d2c616f commit 9c864c2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ android {
shrinkResources false
proguardFiles 'proguard-project.txt'
versionNameSuffix '-debug'
dexcount.enabled = false
dexcount {
enabled false
}
}

release {
Expand Down Expand Up @@ -223,7 +225,7 @@ dependencies {
lumenImplementation 'com.revenuecat.purchases:purchases:2.1.2'

// vpn module
lumenImplementation 'com.cliqz:com.cliqz.vpnlib:1.0.1'
lumenImplementation 'com.cliqz:com.cliqz.vpnlib:1.0.4'

// Testing-only dependencies
testImplementation 'junit:junit:4.12'
Expand Down
44 changes: 44 additions & 0 deletions buildSrc/src/main/groovy/com/cliqz/gradle/TestdroidTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class TestDroidTask extends DefaultTask {
// 5. Download the artifacts and put them in a predefined folder (where Azure/Jenkins can find it)
fetchTestRunArtifacts(runID)
// 6. log error if any test failed, otherwise just return
Float successRatio = errorLogger(runID)
if (successRatio == 1){
logger.info("Test Run was successful")
println("Test Run was successful")
}else if (successRatio < 1 && successRatio > 0.90){
logger.info("Need to get session success Ratios")
Float sessionSuccessRatio = sessionErrorLogger(runID)
if (sessionSuccessRatio < 0.50){
logger.error("Need to check tests that are failing")
throw new Exception('Tests are failing')
}else {
logger.info("Test run was not 100% successful but that's okay")
}
}
}

def getBasicAuth(String apiKey) {
Expand Down Expand Up @@ -155,4 +169,34 @@ class TestDroidTask extends DefaultTask {
logger.error("No session data for test run ${testRunID}")
}
}
def errorLogger(long testRunID){
final url = new URL("https://cloud.bitbar.com/api/me/projects/${PROJECT_ID}/runs/${testRunID}")
final testRun = url.openConnection()
testRun.setRequestProperty('Authorization', "Basic ${getBasicAuth(API_KEY)}")
if (testRun.responseCode == HttpURLConnection.HTTP_OK) {
final testRunResult = slurper.parse(testRun.inputStream)
testRunResult.successRatio
}
else {
logger.error("No Test Run for the given id: ${testRunID}")
}
}
def sessionErrorLogger(long testRunID){
final url = new URL("https://cloud.bitbar.com/api/me/projects/${PROJECT_ID}/runs/${testRunID}/device-sessions")
final sessions = url.openConnection()
sessions.setRequestProperty('Authorization', "Basic ${getBasicAuth(API_KEY)}")
if (sessions.responseCode == HttpURLConnection.HTTP_OK) {
final sessionResults = slurper.parse(sessions.inputStream)
sessionResults.data.each { session ->
println "Device: ${session.device.displayName} ID: ${session.id} SuccessRatio: ${session.successRatio}"
if (session.successRatio < 0.5){
logger.error("Tests are failing on ${session.displayName}")
session.successRatio
}else{
logger.info("Tests are failing but that's okay")
session.successRatio
}
}
}
}
}

0 comments on commit 9c864c2

Please sign in to comment.