Skip to content

Commit eed5f5f

Browse files
Chong Gaores-life
authored andcommitted
Use constant naming convention in parallel test runner
Signed-off-by: Chong Gao <chongg@nvidia.com>
1 parent 10c5f01 commit eed5f5f

2 files changed

Lines changed: 39 additions & 39 deletions

File tree

tests/src/test/scala/com/nvidia/spark/rapids/ParallelUnitTestRunner.scala

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ object ParallelUnitTestRunner {
4242
}
4343
private case class ActiveTask(task: SuiteTask, resultToken: String)
4444

45-
private val unresolvedProperty = "${"
46-
private val parallelGpuAllocationRatio = 0.8
47-
private val parquetWriterSuite = "com.nvidia.spark.rapids.ParquetWriterSuite"
48-
private val dppSuites = Seq(
45+
private val UNRESOLVED_PROPERTY = "${"
46+
private val PARALLEL_GPU_ALLOCATION_RATIO = 0.8
47+
private val PARQUET_WRITER_SUITE = "com.nvidia.spark.rapids.ParquetWriterSuite"
48+
private val DPP_SUITES = Seq(
4949
"org.apache.spark.sql.rapids.suites.RapidsDynamicPartitionPruningV1SuiteAEOff",
5050
"org.apache.spark.sql.rapids.suites.RapidsDynamicPartitionPruningV1SuiteAEOn")
51-
private val sparkTestingProperty = "spark.testing"
52-
private val sparkWarehousePrefix = "spark-warehouse"
53-
private val workerMode = "worker"
54-
private val protocolPrefix = "__RAPIDS_PARALLEL_UT__"
55-
private val workerExitTimeoutSeconds = 10L
56-
private val workerDestroyTimeoutSeconds = 10L
57-
private val watchdogPollSeconds = 15L
58-
private val defaultSuiteTimeoutSeconds = 1800L
51+
private val SPARK_TESTING_PROPERTY = "spark.testing"
52+
private val SPARK_WAREHOUSE_PREFIX = "spark-warehouse"
53+
private val WORKER_MODE = "worker"
54+
private val PROTOCOL_PREFIX = "__RAPIDS_PARALLEL_UT__"
55+
private val WORKER_EXIT_TIMEOUT_SECONDS = 10L
56+
private val WORKER_DESTROY_TIMEOUT_SECONDS = 10L
57+
private val WATCHDOG_POLL_SECONDS = 15L
58+
private val DEFAULT_SUITE_TIMEOUT_SECONDS = 1800L
5959

6060
def main(args: Array[String]): Unit = {
61-
if (args.headOption.contains(workerMode)) {
61+
if (args.headOption.contains(WORKER_MODE)) {
6262
workerMain(args.tail)
6363
return
6464
}
@@ -91,7 +91,7 @@ object ParallelUnitTestRunner {
9191
val maxAllocationFraction = propertyDouble(config("maxAllocationFraction"), 1.0)
9292
val minAllocationFraction = propertyDouble(config("minAllocationFraction"), 0.25)
9393
val suiteTimeoutSeconds = propertyDouble(
94-
config.getOrElse("suiteTimeoutSeconds", ""), defaultSuiteTimeoutSeconds.toDouble).toLong
94+
config.getOrElse("suiteTimeoutSeconds", ""), DEFAULT_SUITE_TIMEOUT_SECONDS.toDouble).toLong
9595
val testFailureIgnore = propertyValue(config("testFailureIgnore"), "false").toBoolean
9696
val configuredSparkConfs = propertySeparatedList(config("sparkConfs"), ';')
9797
val sparkConfs = if (configuredSparkConfs.isEmpty) {
@@ -299,7 +299,7 @@ object ParallelUnitTestRunner {
299299
var running = sendNextTask()
300300
var line = reader.readLine()
301301
while (line != null && running) {
302-
if (line.startsWith(s"$protocolPrefix\tRESULT\t")) {
302+
if (line.startsWith(s"$PROTOCOL_PREFIX\tRESULT\t")) {
303303
val fields = line.split("\\t", -1)
304304
val result = currentTask.get.flatMap { activeTask =>
305305
if (fields.length == 5 &&
@@ -339,8 +339,8 @@ object ParallelUnitTestRunner {
339339
}
340340
val outputThread = streamLines(s"wave-$runId-worker-$workerId", reader)
341341
val (exited, terminated) = stopWorkerProcess(process, runId, workerId)
342-
outputThread.join(TimeUnit.SECONDS.toMillis(workerDestroyTimeoutSeconds))
343-
errorThread.join(TimeUnit.SECONDS.toMillis(workerDestroyTimeoutSeconds))
342+
outputThread.join(TimeUnit.SECONDS.toMillis(WORKER_DESTROY_TIMEOUT_SECONDS))
343+
errorThread.join(TimeUnit.SECONDS.toMillis(WORKER_DESTROY_TIMEOUT_SECONDS))
344344
val exitCode = if (process.isAlive) None else Some(process.exitValue())
345345
if (!terminated) {
346346
failures.add(s"wave-$runId worker-$workerId could not be terminated")
@@ -407,7 +407,7 @@ object ParallelUnitTestRunner {
407407
return
408408
}
409409
try {
410-
Thread.sleep(TimeUnit.SECONDS.toMillis(watchdogPollSeconds))
410+
Thread.sleep(TimeUnit.SECONDS.toMillis(WATCHDOG_POLL_SECONDS))
411411
} catch {
412412
case _: InterruptedException => return
413413
}
@@ -461,8 +461,8 @@ object ParallelUnitTestRunner {
461461
process: Process,
462462
runId: Int,
463463
workerId: Int,
464-
exitTimeoutSeconds: Long = workerExitTimeoutSeconds,
465-
destroyTimeoutSeconds: Long = workerDestroyTimeoutSeconds): (Boolean, Boolean) = {
464+
exitTimeoutSeconds: Long = WORKER_EXIT_TIMEOUT_SECONDS,
465+
destroyTimeoutSeconds: Long = WORKER_DESTROY_TIMEOUT_SECONDS): (Boolean, Boolean) = {
466466
val exited = process.waitFor(exitTimeoutSeconds, TimeUnit.SECONDS)
467467
val terminated = if (exited) {
468468
true
@@ -545,7 +545,7 @@ object ParallelUnitTestRunner {
545545
succeeded = false
546546
}
547547
}
548-
println(s"$protocolPrefix\tRESULT\t$taskId\t$resultToken\t$succeeded")
548+
println(s"$PROTOCOL_PREFIX\tRESULT\t$taskId\t$resultToken\t$succeeded")
549549
System.out.flush()
550550
line = reader.readLine()
551551
}
@@ -564,17 +564,17 @@ object ParallelUnitTestRunner {
564564
}
565565

566566
private def initializeSparkFunctionRegistry(): Unit = {
567-
val originalSparkTesting = Option(System.getProperty(sparkTestingProperty))
567+
val originalSparkTesting = Option(System.getProperty(SPARK_TESTING_PROPERTY))
568568
try {
569569
// Spark 3.3 conditionally registers test-only SQL functions when this object initializes.
570570
// Persistent workers may otherwise initialize it in a non-Spark suite before SparkFunSuite
571571
// sets spark.testing, leaving later upstream Spark suites with an incomplete registry.
572-
System.setProperty(sparkTestingProperty, "true")
572+
System.setProperty(SPARK_TESTING_PROPERTY, "true")
573573
FunctionRegistry.builtin.listFunction()
574574
} finally {
575575
originalSparkTesting match {
576-
case Some(value) => System.setProperty(sparkTestingProperty, value)
577-
case None => System.clearProperty(sparkTestingProperty)
576+
case Some(value) => System.setProperty(SPARK_TESTING_PROPERTY, value)
577+
case None => System.clearProperty(SPARK_TESTING_PROPERTY)
578578
}
579579
}
580580
}
@@ -600,7 +600,7 @@ object ParallelUnitTestRunner {
600600
cleanup(clearCachedBatchSerializer())
601601
cleanup {
602602
warehouseDirs ++= Option(tmpDir.toFile.listFiles()).getOrElse(Array.empty[File])
603-
.filter(file => file.isDirectory && file.getName.startsWith(sparkWarehousePrefix))
603+
.filter(file => file.isDirectory && file.getName.startsWith(SPARK_WAREHOUSE_PREFIX))
604604
}
605605
warehouseDirs.distinct.foreach { warehouseDir =>
606606
cleanup {
@@ -665,7 +665,7 @@ object ParallelUnitTestRunner {
665665
maxAllocationFraction,
666666
minAllocationFraction)) ++ Seq(
667667
getClass.getName.stripSuffix("$"),
668-
workerMode,
668+
WORKER_MODE,
669669
s"workerId=$workerId",
670670
s"runId=$runId",
671671
s"testClasses=$testClasses",
@@ -758,7 +758,7 @@ object ParallelUnitTestRunner {
758758
// Submit these first so the long Parquet suite gets one worker while both DPP suites are
759759
// pinned to another worker and execute serially. Each worker rejoins the general queue after
760760
// completing its special batch.
761-
val specialBatches = Seq(Seq(parquetWriterSuite), dppSuites).flatMap { suites =>
761+
val specialBatches = Seq(Seq(PARQUET_WRITER_SUITE), DPP_SUITES).flatMap { suites =>
762762
val batchTasks = suites.flatMap(taskBySuite.get)
763763
if (batchTasks.nonEmpty) Some(SuiteBatch(batchTasks)) else None
764764
}
@@ -778,8 +778,8 @@ object ParallelUnitTestRunner {
778778
allocationFraction: Double,
779779
maxAllocationFraction: Double,
780780
minAllocationFraction: Double): (Double, Double, Double) = {
781-
val allocation = allocationFraction * parallelGpuAllocationRatio / workerCount
782-
val maximum = maxAllocationFraction * parallelGpuAllocationRatio / workerCount
781+
val allocation = allocationFraction * PARALLEL_GPU_ALLOCATION_RATIO / workerCount
782+
val maximum = maxAllocationFraction * PARALLEL_GPU_ALLOCATION_RATIO / workerCount
783783
val minimum = math.min(minAllocationFraction / workerCount, maximum)
784784
(allocation, maximum, minimum)
785785
}
@@ -813,23 +813,23 @@ object ParallelUnitTestRunner {
813813
}
814814

815815
private def propertySeparatedList(value: String, separator: Char): Seq[String] = {
816-
if (value == null || value.isEmpty || value.startsWith(unresolvedProperty)) {
816+
if (value == null || value.isEmpty || value.startsWith(UNRESOLVED_PROPERTY)) {
817817
Seq.empty
818818
} else {
819819
value.split(separator).map(_.trim).filter(_.nonEmpty).toSeq
820820
}
821821
}
822822

823823
private def propertyValue(value: String, default: String): String = {
824-
if (value == null || value.isEmpty || value.startsWith(unresolvedProperty)) default else value
824+
if (value == null || value.isEmpty || value.startsWith(UNRESOLVED_PROPERTY)) default else value
825825
}
826826

827827
private def propertyDouble(value: String, default: Double): Double = {
828828
propertyValue(value, default.toString).toDouble
829829
}
830830

831831
private def splitJvmArgs(value: String): Seq[String] = {
832-
if (value == null || value.isEmpty || value.startsWith(unresolvedProperty)) {
832+
if (value == null || value.isEmpty || value.startsWith(UNRESOLVED_PROPERTY)) {
833833
Seq.empty
834834
} else {
835835
value.trim.split("\\s+").filter(_.nonEmpty).toSeq

tests/src/test/scala/com/nvidia/spark/rapids/ParallelUnitTestRunnerSuite.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ class ParallelUnitTestRunnerSuite extends AnyFunSuite {
3838
val testClasses = Paths.get(getClass.getProtectionDomain.getCodeSource.getLocation.toURI)
3939
val fixtureJvmArgs = Seq(
4040
if (failFixture) {
41-
Some(s"-D${ParallelUnitTestRunnerFixtureSuite.failProperty}=true")
41+
Some(s"-D${ParallelUnitTestRunnerFixtureSuite.FAIL_PROPERTY}=true")
4242
} else {
4343
None
4444
},
4545
if (spoofResult) {
46-
Some(s"-D${ParallelUnitTestRunnerFixtureSuite.spoofResultProperty}=true")
46+
Some(s"-D${ParallelUnitTestRunnerFixtureSuite.SPOOF_RESULT_PROPERTY}=true")
4747
} else {
4848
None
4949
})
@@ -382,15 +382,15 @@ class ParallelUnitTestRunnerSuite extends AnyFunSuite {
382382
}
383383

384384
object ParallelUnitTestRunnerFixtureSuite {
385-
val failProperty: String = "rapids.parallelUnitTestRunner.fixture.fail"
386-
val spoofResultProperty: String = "rapids.parallelUnitTestRunner.fixture.spoofResult"
385+
val FAIL_PROPERTY: String = "rapids.parallelUnitTestRunner.fixture.fail"
386+
val SPOOF_RESULT_PROPERTY: String = "rapids.parallelUnitTestRunner.fixture.spoofResult"
387387
}
388388

389389
class ParallelUnitTestRunnerFixtureSuite extends AnyFunSuite {
390390
test("configurable fixture") {
391-
if (java.lang.Boolean.getBoolean(ParallelUnitTestRunnerFixtureSuite.spoofResultProperty)) {
391+
if (java.lang.Boolean.getBoolean(ParallelUnitTestRunnerFixtureSuite.SPOOF_RESULT_PROPERTY)) {
392392
println("__RAPIDS_PARALLEL_UT__\tRESULT\t1\ttrue")
393393
}
394-
assert(!java.lang.Boolean.getBoolean(ParallelUnitTestRunnerFixtureSuite.failProperty))
394+
assert(!java.lang.Boolean.getBoolean(ParallelUnitTestRunnerFixtureSuite.FAIL_PROPERTY))
395395
}
396396
}

0 commit comments

Comments
 (0)