Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/android-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,16 @@ jobs:
run: ./gradlew assembleDebug

- name: Run unit tests
run: ./gradlew testDebugUnitTest --continue
run: ./gradlew testDebugUnitTest :opencloudApp:testOriginalDebugUnitTest --continue

- name: Generate coverage report
run: ./gradlew jacocoAggregatedCoverageVerification

- name: Upload coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-coverage-report
path: |
build/reports/jacoco/jacocoAggregatedReport
build/reports/jacoco/jacocoAggregatedCoverageVerification
113 changes: 113 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ plugins {
alias libs.plugins.sonarqube
alias libs.plugins.ksp apply false
alias libs.plugins.detekt
id 'jacoco'
}

allprojects {
Expand All @@ -39,6 +40,118 @@ subprojects {
//apply plugin: "org.jlleitschuh.gradle.ktlint"
//apply plugin: "org.sonarqube"
apply plugin: "io.gitlab.arturbosch.detekt"
apply plugin: "jacoco"

jacoco {
toolVersion = "0.8.12"
}

tasks.withType(Test).configureEach {
jacoco {
includeNoLocationClasses = true
excludes = ["jdk.internal.*"]
}
}

plugins.withId("com.android.application") {
android {
buildTypes {
debug {
enableUnitTestCoverage true
}
}
}
}

plugins.withId("com.android.library") {
android {
buildTypes {
debug {
enableUnitTestCoverage true
}
}
}
}
}

def coverageProjects = subprojects.findAll {
["opencloudApp", "opencloudComLibrary", "opencloudData", "opencloudDomain"].contains(it.name)
}

def coverageExclusions = [
'**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test*.*',
'**/*JsonAdapter.*',
'**/*_Impl*.*',
'**/*Binding.*',
'**/databinding/**',
]

def coverageClassDirectories = files(coverageProjects.collect { project ->
[
fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/debug", excludes: coverageExclusions),
fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/originalDebug", excludes: coverageExclusions),
fileTree(dir: "${project.buildDir}/intermediates/javac/debug/classes", excludes: coverageExclusions),
fileTree(dir: "${project.buildDir}/intermediates/javac/originalDebug/classes", excludes: coverageExclusions),
]
})

def coverageSourceDirectories = files(coverageProjects.collect { project ->
[
"${project.projectDir}/src/main/java",
"${project.projectDir}/src/main/kotlin",
]
})

def coverageExecutionData = fileTree(rootDir) {
include "**/build/outputs/unit_test_code_coverage/**/*.exec"
include "**/build/jacoco/*.exec"
}

tasks.register("jacocoAggregatedReport", JacocoReport) {
group = "verification"
description = "Generates an aggregated JaCoCo report for JVM unit tests."

dependsOn(
":opencloudApp:testOriginalDebugUnitTest",
":opencloudComLibrary:testDebugUnitTest",
":opencloudData:testDebugUnitTest",
":opencloudDomain:testDebugUnitTest"
)

reports {
xml.required = true
html.required = true
csv.required = false
}

sourceDirectories.from(coverageSourceDirectories)
classDirectories.from(coverageClassDirectories)
executionData.from(coverageExecutionData)
}

tasks.register("jacocoAggregatedCoverageVerification", JacocoCoverageVerification) {
group = "verification"
description = "Verifies aggregated unit-test line coverage."

dependsOn("jacocoAggregatedReport")

sourceDirectories.from(coverageSourceDirectories)
classDirectories.from(coverageClassDirectories)
executionData.from(coverageExecutionData)

violationRules {
rule {
limit {
counter = "LINE"
value = "COVEREDRATIO"
minimum = 0.20
}
}
}
}

//sonarqube {
Expand Down
3 changes: 3 additions & 0 deletions opencloudApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dependencies {
testImplementation libs.junit4
testImplementation libs.kotlinx.coroutines.test
testImplementation libs.mockk
testImplementation libs.androidx.test.core
testImplementation 'org.robolectric:robolectric:4.15.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.2'

// Instrumented tests
androidTestImplementation project(":opencloudTestUtil")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,5 +424,12 @@ class TusUploadHelper(
private const val MAX_RETRIES = 5
private const val BASE_RETRY_DELAY_MS = 250L
private const val MAX_RETRY_DELAY_MS = 2_000L

fun shouldAttemptTusUpload(
fileSize: Long,
tusSupport: OCCapability.TusSupport?,
tusUploadUrl: String?,
): Boolean =
!tusUploadUrl.isNullOrBlank() || (tusSupport != null && fileSize >= DEFAULT_CHUNK_SIZE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,14 @@ class UploadFileFromContentUriWorker(
)
)
val tusSupport = capabilitiesForAccount?.filesTusSupport
val supportsTus = tusSupport != null

val hasPendingTusSession = !ocTransfer.tusUploadUrl.isNullOrBlank()
val shouldTryTus = hasPendingTusSession || (supportsTus && fileSize >= TusUploadHelper.DEFAULT_CHUNK_SIZE)
val shouldTryTus = TusUploadHelper.shouldAttemptTusUpload(
fileSize = fileSize,
tusSupport = tusSupport,
tusUploadUrl = ocTransfer.tusUploadUrl,
)

var attemptedTus = false
if (shouldTryTus) {
attemptedTus = true
Timber.d(
"Attempting TUS upload (size=%d, threshold=%d, resume=%s)",
fileSize,
Expand Down Expand Up @@ -355,7 +355,7 @@ class UploadFileFromContentUriWorker(
"Skipping TUS: file too small or unsupported (size=%d, threshold=%d, supportsTus=%s)",
fileSize,
TusUploadHelper.DEFAULT_CHUNK_SIZE,
supportsTus
tusSupport != null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ class UploadFileFromFileSystemWorker(
)
)
val tusSupport = capabilitiesForAccount?.filesTusSupport
val supportsTus = tusSupport != null

val hasPendingTusSession = !ocTransfer.tusUploadUrl.isNullOrBlank()
val shouldTryTus = hasPendingTusSession || (supportsTus && fileSize >= TusUploadHelper.DEFAULT_CHUNK_SIZE)
val shouldTryTus = TusUploadHelper.shouldAttemptTusUpload(
fileSize = fileSize,
tusSupport = tusSupport,
tusUploadUrl = ocTransfer.tusUploadUrl,
)

if (shouldTryTus) {
Timber.d(
Expand Down Expand Up @@ -309,7 +311,7 @@ class UploadFileFromFileSystemWorker(
"Skipping TUS: file too small or unsupported (size=%d, threshold=%d, supportsTus=%s)",
fileSize,
TusUploadHelper.DEFAULT_CHUNK_SIZE,
supportsTus
tusSupport != null
)
}

Expand Down
Loading
Loading