Skip to content

Commit f5f73bb

Browse files
committed
improve test
1 parent e768142 commit f5f73bb

1 file changed

Lines changed: 32 additions & 35 deletions

File tree

spark/src/test/scala/org/apache/spark/sql/comet/CometPlanStabilitySuite.scala

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import java.nio.charset.StandardCharsets
2424

2525
import scala.collection.mutable
2626

27+
import org.junit.ComparisonFailure
28+
2729
import org.apache.commons.io.FileUtils
2830
import org.apache.spark.SparkContext
2931
import org.apache.spark.internal.config.{MEMORY_OFFHEAP_ENABLED, MEMORY_OFFHEAP_SIZE}
@@ -141,50 +143,45 @@ trait CometPlanStabilitySuite extends DisableAdaptiveExecutionSuite with TPCDSBa
141143
val foundMatch = isApproved(dir, actualSimplified, actualExplain)
142144

143145
if (!foundMatch) {
144-
// show diff with last approved
146+
// read approved files
145147
val approvedSimplifiedFile = new File(dir, "simplified.txt")
146148
val approvedExplainFile = new File(dir, "explain.txt")
149+
val approvedSimplified =
150+
FileUtils.readFileToString(approvedSimplifiedFile, StandardCharsets.UTF_8)
151+
val approvedExplain =
152+
FileUtils.readFileToString(approvedExplainFile, StandardCharsets.UTF_8)
147153

154+
// write actual files out for debugging
148155
val actualSimplifiedFile = new File(tempDir, s"$name.actual.simplified.txt")
149156
val actualExplainFile = new File(tempDir, s"$name.actual.explain.txt")
150-
151-
val simplifiedFile = new File(dir, "simplified.txt")
152-
val approvedSimplified =
153-
FileUtils.readFileToString(simplifiedFile, StandardCharsets.UTF_8)
154-
val explainFile = new File(dir, "explain.txt")
155-
val approvedExplain = FileUtils.readFileToString(explainFile, StandardCharsets.UTF_8)
156-
157-
// write out for debugging
158157
FileUtils.writeStringToFile(actualSimplifiedFile, actualSimplified, StandardCharsets.UTF_8)
159158
FileUtils.writeStringToFile(actualExplainFile, actualExplain, StandardCharsets.UTF_8)
160159

161-
if (approvedSimplified != actualSimplified) {
162-
fail(s"""
163-
|Plans did not match:
164-
|last approved simplified plan: ${approvedSimplifiedFile.getAbsolutePath}
165-
|
166-
|$approvedSimplified
167-
|
168-
|actual simplified plan: ${actualSimplifiedFile.getAbsolutePath}
169-
|
170-
|$actualSimplified
171-
""".stripMargin)
172-
173-
} else if (approvedExplain != actualExplain) {
174-
fail(s"""
175-
|Plans did not match:
176-
|last approved explain plan: ${approvedExplainFile.getAbsolutePath}
177-
|
178-
|$approvedExplain
179-
|
180-
|actual explain plan: ${actualExplainFile.getAbsolutePath}
181-
|
182-
|$actualExplain
183-
""".stripMargin)
160+
comparePlans(
161+
"simplified",
162+
approvedSimplified,
163+
actualSimplified,
164+
approvedSimplifiedFile,
165+
actualSimplifiedFile)
166+
comparePlans(
167+
"explain",
168+
approvedExplain,
169+
actualExplain,
170+
approvedExplainFile,
171+
actualExplainFile)
172+
}
173+
}
184174

185-
} else {
186-
fail("unreachable")
187-
}
175+
private def comparePlans(
176+
planType: String,
177+
expected: String,
178+
actual: String,
179+
expectedFile: File,
180+
actualFile: File): Unit = {
181+
if (expected != actual) {
182+
val message =
183+
s"Expected $planType plan in ${expectedFile.getAbsolutePath} did not match actual $planType plan in ${actualFile.getAbsolutePath}"
184+
throw new ComparisonFailure(message, expected, actual)
188185
}
189186
}
190187

0 commit comments

Comments
 (0)