Skip to content

Commit 82407b4

Browse files
committed
Add 'TaskLockService'
Resolves #39
1 parent 0c918e8 commit 82407b4

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright the GradleX team.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.gradlex.javamodule.testing;
18+
19+
import org.gradle.api.services.BuildService;
20+
import org.gradle.api.services.BuildServiceParameters;
21+
22+
/**
23+
* No-op service that can serve as 'lock' to prevent multiple test tasks from running in parallel:
24+
* usesService(gradle.sharedServices.registerIfAbsent(TaskLockService.NAME, TaskLockService::class) { maxParallelUsages = 1 })
25+
*/
26+
public abstract class TaskLockService implements BuildService<BuildServiceParameters.None> {
27+
public static String NAME = "taskLock";
28+
}

src/test/groovy/org/gradlex/javamodule/testing/test/CustomizationTest.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,30 @@ class CustomizationTest extends Specification {
7575
then:
7676
result.task(":app:test").outcome == TaskOutcome.SUCCESS
7777
}
78+
79+
def "can use task lock service"() {
80+
given:
81+
appBuildFile.text = 'import org.gradlex.javamodule.testing.TaskLockService\n\n' + appBuildFile.text
82+
appBuildFile << '''
83+
javaModuleTesting.whitebox(testing.suites.getByName<JvmTestSuite>("test") {
84+
targets.all {
85+
testTask {
86+
usesService(gradle.sharedServices.registerIfAbsent(TaskLockService.NAME, TaskLockService::class) { maxParallelUsages = 1 })
87+
}
88+
}
89+
}) {
90+
requires.add("org.junit.jupiter.api")
91+
}
92+
'''
93+
appModuleInfoFile << '''
94+
module org.example.app {
95+
}
96+
'''
97+
98+
when:
99+
def result = runTests()
100+
101+
then:
102+
result.task(":app:test").outcome == TaskOutcome.SUCCESS
103+
}
78104
}

0 commit comments

Comments
 (0)