Skip to content

Commit af252f5

Browse files
authored
Add Jacoco code-coverage reports generation and aggregation (temporalio#1171)
1 parent 31f606e commit af252f5

File tree

10 files changed

+108
-156
lines changed

10 files changed

+108
-156
lines changed

.github/workflows/coverage.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Code Coverage
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
code-coverage:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Set up Java
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '11'
20+
distribution: 'temurin'
21+
22+
- name: Set up Gradle
23+
uses: gradle/gradle-build-action@v2
24+
25+
- name: Run Tests
26+
run: ./gradlew test -x checkLicenseMain -x checkLicenses -x spotlessCheck -x spotlessApply -Pjacoco
27+
continue-on-error: true
28+
29+
- name: Run Test Coverage
30+
run: ./gradlew testCodeCoverageReport -Pjacoco
31+
32+
- name: Publish Coverage
33+
env:
34+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
35+
run: ./gradlew coverallsJacoco -Pjacoco

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Temporal Java SDK [![Build status](https://badge.buildkite.com/663f6d1be81be6700c28c242b35905f20b68c4fda7b2c7c4e3.svg?branch=master)](https://buildkite.com/temporal/java-sdk-public)
1+
# Temporal Java SDK [![Build status](https://badge.buildkite.com/663f6d1be81be6700c28c242b35905f20b68c4fda7b2c7c4e3.svg?branch=master)](https://buildkite.com/temporal/java-sdk-public) [![Coverage Status](https://coveralls.io/repos/github/temporalio/sdk-java/badge.svg?branch=master)](https://coveralls.io/github/temporalio/sdk-java?branch=master)
22

33
[Temporal](https://github.com/temporalio/temporal) is a Workflow-as-Code platform for building and operating
44
resilient applications using developer-friendly primitives, instead of constantly fighting your infrastructure.

build.gradle

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
buildscript {
22
ext {
33
palantirGitVersionVersion = "${JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_11) ? '0.15.0' : '0.13.0'}"
4+
kotlinVersion = "${JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16) ? '1.5.32' : '1.4.32'}"
45
}
56
}
67

@@ -10,6 +11,12 @@ plugins {
1011
id 'com.palantir.git-version' version "${palantirGitVersionVersion}" apply false
1112
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
1213
id 'com.diffplug.spotless' version '6.9.0' apply false
14+
id 'com.github.nbaztec.coveralls-jacoco' version "1.2.14" apply false
15+
16+
// id 'org.jetbrains.kotlin.jvm' version '1.4.32'
17+
// id 'org.jetbrains.kotlin.jvm' version '1.5.32'
18+
// id 'org.jetbrains.kotlin.jvm' version '1.6.20'
19+
id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}" apply false
1320
id 'base'
1421
}
1522

@@ -50,6 +57,6 @@ apply from: "$rootDir/gradle/errorprone.gradle"
5057
apply from: "$rootDir/gradle/licensing.gradle"
5158
apply from: "$rootDir/gradle/publishing.gradle"
5259
apply from: "$rootDir/gradle/dependencyManagement.gradle"
53-
if (project.project.hasProperty("jacoco")) {
60+
if (project.hasProperty("jacoco")) {
5461
apply from: "$rootDir/gradle/jacoco.gradle"
5562
}

gradle/jacoco.gradle

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
1-
//./gradlew jacocoTestReport -Pjacoco
1+
//./gradlew testCodeCoverageReport -Pjacoco
2+
3+
apply plugin: 'jacoco-report-aggregation'
4+
apply plugin: 'com.github.nbaztec.coveralls-jacoco'
5+
6+
dependencies {
7+
jacocoAggregation project(':temporal-kotlin')
8+
jacocoAggregation project(':temporal-opentracing')
9+
jacocoAggregation project(':temporal-remote-data-encoder')
10+
jacocoAggregation project(':temporal-sdk')
11+
jacocoAggregation project(':temporal-serviceclient')
12+
jacocoAggregation project(':temporal-test-server')
13+
jacocoAggregation project(':temporal-testing')
14+
}
15+
16+
def jacocoExclusions = [
17+
'**/io/temporal/api/**',
18+
'**/gogoproto/**'
19+
]
20+
21+
reporting {
22+
reports {
23+
testCodeCoverageReport(JacocoCoverageReport) {
24+
testType = TestSuiteType.UNIT_TEST
25+
}
26+
}
27+
}
28+
29+
testCodeCoverageReport {
30+
reports {
31+
csv.required = true
32+
xml.required = true
33+
}
34+
35+
getClassDirectories().setFrom(files(
36+
subprojects.collect {it.fileTree(dir: "${it.buildDir}/classes", exclude: jacocoExclusions)}
37+
))
38+
}
39+
40+
coverallsJacoco {
41+
reportPath = "build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
42+
reportSourceSets = subprojects.sourceSets.main.allSource.srcDirs.flatten()
43+
}
44+
45+
tasks.coverallsJacoco.dependsOn(testCodeCoverageReport)
246

347
subprojects {
448
apply plugin: 'jacoco'
@@ -9,20 +53,22 @@ subprojects {
953

1054
jacocoTestReport {
1155
reports {
12-
xml.enabled false
56+
xml.enabled true
1357
csv.enabled true
1458
}
1559

1660
afterEvaluate {
1761
classDirectories.setFrom(files(classDirectories.files.collect {
18-
fileTree(dir: it, exclude: ["**/generated/**"])
62+
fileTree(dir: it, exclude: jacocoExclusions)
1963
}))
2064
}
2165
}
2266

2367
test {
2468
// Some tests don't work with Jacoco.
25-
// It's not a bug, they are just written assuming that they are working not with a proxy, but a pure instance
69+
// It's not a bug, they are just written assuming that they are working not with a proxy, but a pure instance.
2670
exclude 'io/temporal/workflow/KotlinAsyncChildWorkflowTest.class'
2771
}
72+
73+
testCodeCoverageReport.dependsOn jacocoTestReport
2874
}

gradle/java.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ subprojects {
5353
showStandardStreams true
5454
}
5555
forkEvery = 1
56-
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
56+
57+
var coresDivider = project.hasProperty("jacoco") ? 4 : 2 // penalize jacoco build to reduce load and random timeouts
58+
maxParallelForks = Math.max(Runtime.runtime.availableProcessors().intdiv(coresDivider), 1) ?: 1
59+
5760
// Captures the list of failed tests to log after build is done.
5861
afterTest { TestDescriptor descriptor, TestResult result ->
5962
if (result.resultType == org.gradle.api.tasks.testing.TestResult.ResultType.FAILURE) {

temporal-kotlin/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
1-
buildscript {
2-
ext {
3-
kotlinVersion = "${JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_16) ? '1.5.32' : '1.4.32'}"
4-
}
5-
}
6-
71
plugins {
8-
// id 'org.jetbrains.kotlin.jvm' version '1.4.32'
9-
// id 'org.jetbrains.kotlin.jvm' version '1.5.32'
10-
// id 'org.jetbrains.kotlin.jvm' version '1.6.20'
11-
id 'org.jetbrains.kotlin.jvm' version "${kotlinVersion}"
122
id 'org.jlleitschuh.gradle.ktlint' version '10.3.0'
133
}
144

temporal-sdk/src/main/java/io/temporal/internal/Config.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package io.temporal.internal;
2222

23-
public class Config {
23+
public abstract class Config {
24+
private Config() {}
25+
2426
/** Force new workflow task after workflow task timeout multiplied by this coefficient. */
2527
public static final double WORKFLOW_TAK_HEARTBEAT_COEFFICIENT = 4d / 5d;
2628
}

temporal-sdk/src/main/java/io/temporal/internal/sync/WorkflowTimers.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

temporal-sdk/src/test/java/io/temporal/worker/LocalActivityWorkerOnlyTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
package io.temporal.worker;
2222

23-
import static org.junit.Assert.assertTrue;
23+
import static org.hamcrest.CoreMatchers.instanceOf;
24+
import static org.hamcrest.MatcherAssert.assertThat;
25+
import static org.junit.Assert.assertThrows;
2426

2527
import io.temporal.activity.ActivityOptions;
2628
import io.temporal.activity.LocalActivityOptions;
@@ -56,11 +58,9 @@ public void verifyThatLocalActivitiesAreExecuted() {
5658
@Test
5759
public void verifyThatNormalActivitiesAreTimedOut() {
5860
NoArgsWorkflow activityWorkflow = testWorkflowRule.newWorkflowStub(NoArgsWorkflow.class);
59-
try {
60-
activityWorkflow.execute();
61-
} catch (WorkflowFailedException e) {
62-
assertTrue(e.getCause().getCause() instanceof TimeoutFailure);
63-
}
61+
WorkflowFailedException workflowFailedException =
62+
assertThrows(WorkflowFailedException.class, activityWorkflow::execute);
63+
assertThat(workflowFailedException.getCause().getCause(), instanceOf(TimeoutFailure.class));
6464
}
6565

6666
@WorkflowInterface

temporal-sdk/src/test/java/io/temporal/workflow/WorkflowTaskFailureBackoffTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class WorkflowTaskFailureBackoffTest {
5656
.reportEvery(com.uber.m3.util.Duration.ofMillis(10)))
5757
.build();
5858

59-
@Test
59+
@Test(timeout = 15_000)
6060
public void testWorkflowTaskFailureBackoff() {
6161
testWorkflowTaskFailureBackoffReplayCount = 0;
6262
WorkflowOptions options =

0 commit comments

Comments
 (0)