-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDefaultTestExecuter.scala
More file actions
125 lines (109 loc) · 5.39 KB
/
Copy pathDefaultTestExecuter.scala
File metadata and controls
125 lines (109 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package org.podval.tools.test.task
import org.gradle.api.file.FileTree
import org.gradle.api.internal.classpath.ModuleRegistry
import org.gradle.api.internal.tasks.testing.{JvmTestExecutionSpec, TestClassProcessor, TestExecuter, TestFramework,
TestResultProcessor, WorkerTestClassProcessorFactory}
import org.gradle.api.internal.tasks.testing.detection.{DefaultTestClassScanner, ForkedTestClasspathFactory,
TestFrameworkDetector}
import org.gradle.api.internal.tasks.testing.filter.DefaultTestFilter
import org.gradle.api.internal.tasks.testing.processors.{MaxNParallelTestClassProcessor, PatternMatchTestClassProcessor,
RestartEveryNTestClassProcessor, RunPreviousFailedFirstTestClassProcessor, TestMainAction}
import org.gradle.api.internal.tasks.testing.worker.{ForkedTestClasspath, ForkingTestClassProcessor}
import org.gradle.api.logging.{Logger, Logging}
import org.gradle.api.Action
import org.gradle.internal.Factory
import org.gradle.internal.actor.ActorFactory
import org.gradle.internal.time.Clock
import org.gradle.internal.work.WorkerLeaseService
import org.gradle.process.internal.worker.{WorkerProcessBuilder, WorkerProcessFactory}
import org.gradle.process.JavaForkOptions
import org.podval.tools.platform.Reflection
import java.io.File
// Translated and improved org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter.
// This is the only Gradle class that I need to fork, modify and maintain -
// to use NonForkingTestClassProcessor needed for Scala.js and Scala Native tests.
open class DefaultTestExecuter(
workerFactory: WorkerProcessFactory,
actorFactory: ActorFactory,
moduleRegistry: ModuleRegistry,
workerLeaseService: WorkerLeaseService,
maxWorkerCount: Int,
clock: Clock,
testFilter: DefaultTestFilter
) extends TestExecuter[JvmTestExecutionSpec]:
private val logger: Logger = Logging.getLogger(getClass)
private val testClasspathFactory: ForkedTestClasspathFactory = ForkedTestClasspathFactory(moduleRegistry)
private var testClassProcessor: Option[TestClassProcessor] = None
override def stopNow(): Unit = testClassProcessor.foreach(_.stopNow())
override def execute(testExecutionSpec: JvmTestExecutionSpec, testResultProcessor: TestResultProcessor): Unit =
val testFramework: TestFramework = testExecutionSpec.getTestFramework
val testInstanceFactory: WorkerTestClassProcessorFactory = testFramework.getProcessorFactory
val forkedTestClasspath: ForkedTestClasspath = testClasspathFactory.create(
testExecutionSpec.getClasspath,
testExecutionSpec.getModulePath
)
val forkingProcessorFactory: Factory[TestClassProcessor] = new Factory[TestClassProcessor]:
override def create: TestClassProcessor =
createTestClassProcessor(
workerLeaseService,
workerFactory,
testInstanceFactory,
testExecutionSpec.getJavaForkOptions,
forkedTestClasspath,
testFramework.getWorkerConfigurationAction
)
val reforkingProcessorFactory: Factory[TestClassProcessor] = new Factory[TestClassProcessor]:
override def create: TestClassProcessor = RestartEveryNTestClassProcessor(
forkingProcessorFactory,
testExecutionSpec.getForkEvery
)
val processor: TestClassProcessor =
PatternMatchTestClassProcessor(testFilter,
RunPreviousFailedFirstTestClassProcessor(testExecutionSpec.getPreviousFailedTestClasses,
MaxNParallelTestClassProcessor(getMaxParallelForks(testExecutionSpec), reforkingProcessorFactory, actorFactory)))
testClassProcessor = Some(processor)
val testClassFiles: FileTree = testExecutionSpec.getCandidateClassFiles
val testFrameworkDetector: Option[TestFrameworkDetector] =
if !testExecutionSpec.isScanForTestClasses || testFramework.getDetector == null then None else Some:
val result: TestFrameworkDetector = testFramework.getDetector
result.setTestClasses(java.util.ArrayList[File](testExecutionSpec.getTestClassesDirs.getFiles))
result.setTestClasspath(
Reflection.Invoke[java.util.List[File], ForkedTestClasspath]("getApplicationClasspath")(forkedTestClasspath)
)
result
TestMainAction(
DefaultTestClassScanner(testClassFiles, testFrameworkDetector.orNull, processor),
processor,
testResultProcessor,
workerLeaseService,
clock,
testExecutionSpec.getPath,
"Gradle Test Run " + testExecutionSpec.getIdentityPath
).run()
protected def createTestClassProcessor(
workerLeaseService: WorkerLeaseService,
workerProcessFactory: WorkerProcessFactory,
workerTestClassProcessorFactory: WorkerTestClassProcessorFactory,
javaForkOptions: JavaForkOptions,
classpath: ForkedTestClasspath,
workerConfigurationAction: Action[WorkerProcessBuilder]
): TestClassProcessor = ForkingTestClassProcessor(
workerLeaseService,
workerProcessFactory,
workerTestClassProcessorFactory,
javaForkOptions,
classpath,
workerConfigurationAction
)
private def getMaxParallelForks(testExecutionSpec: JvmTestExecutionSpec): Int =
var maxParallelForks: Int = testExecutionSpec.getMaxParallelForks
if maxParallelForks > maxWorkerCount then
logger.info(
"{}.maxParallelForks ({}) is larger than max-workers ({}), forcing it to {}",
testExecutionSpec.getPath,
maxParallelForks,
maxWorkerCount,
maxWorkerCount
)
maxParallelForks = maxWorkerCount
maxParallelForks