Skip to content

Commit 8b2e4e8

Browse files
committed
Hacky WIP towards speculatively running w/o reset(), then retrying with it.
1 parent f73379b commit 8b2e4e8

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveComparisonTest.scala

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ abstract class HiveComparisonTest
209209
}
210210

211211
val installHooksCommand = "(?i)SET.*hooks".r
212-
def createQueryTest(testCaseName: String, sql: String, reset: Boolean = true) {
212+
def createQueryTest(
213+
testCaseName: String,
214+
sql: String,
215+
reset: Boolean = true,
216+
tryWithoutResettingFirst: Boolean = false) {
213217
// testCaseName must not contain ':', which is not allowed to appear in a filename of Windows
214218
assert(!testCaseName.contains(":"))
215219

@@ -240,9 +244,6 @@ abstract class HiveComparisonTest
240244
test(testCaseName) {
241245
logDebug(s"=== HIVE TEST: $testCaseName ===")
242246

243-
// Clear old output for this testcase.
244-
outputDirectories.map(new File(_, testCaseName)).filter(_.exists()).foreach(_.delete())
245-
246247
val sqlWithoutComment =
247248
sql.split("\n").filterNot(l => l.matches("--.*(?<=[^\\\\]);")).mkString("\n")
248249
val allQueries =
@@ -269,7 +270,10 @@ abstract class HiveComparisonTest
269270
}.mkString("\n== Console version of this test ==\n", "\n", "\n")
270271
}
271272

272-
try {
273+
def doTest(reset: Boolean, isSpeculative: Boolean = false): Unit = {
274+
// Clear old output for this testcase.
275+
outputDirectories.map(new File(_, testCaseName)).filter(_.exists()).foreach(_.delete())
276+
273277
if (reset) {
274278
TestHive.reset()
275279
}
@@ -430,12 +434,36 @@ abstract class HiveComparisonTest
430434
""".stripMargin
431435

432436
stringToFile(new File(wrongDirectory, testCaseName), errorMessage + consoleTestCase)
433-
fail(errorMessage)
437+
if (isSpeculative && !reset) {
438+
// TODO: log this at a very low level that won't appear in the console appender
439+
// then throw a custom exception
440+
fail("Failed on first run; retrying")
441+
} else {
442+
fail(errorMessage)
443+
}
434444
}
435445
}
436446

437447
// Touch passed file.
438448
new FileOutputStream(new File(passedDirectory, testCaseName)).close()
449+
}
450+
451+
try {
452+
try {
453+
if (tryWithoutResettingFirst) {
454+
doTest(reset = false, isSpeculative = true)
455+
} else {
456+
doTest(reset)
457+
}
458+
} catch {
459+
case tf: org.scalatest.exceptions.TestFailedException =>
460+
if (tryWithoutResettingFirst) {
461+
logWarning("Test failed without reset(); retrying with reset()")
462+
doTest(reset = true)
463+
} else {
464+
throw tf
465+
}
466+
}
439467
} catch {
440468
case tf: org.scalatest.exceptions.TestFailedException => throw tf
441469
case originalException: Exception =>

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQueryFileTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract class HiveQueryFileTest extends HiveComparisonTest {
5959
runAll) {
6060
// Build a test case and submit it to scala test framework...
6161
val queriesString = fileToString(testCaseFile)
62-
createQueryTest(testCaseName, queriesString)
62+
createQueryTest(testCaseName, queriesString, reset = true, tryWithoutResettingFirst = true)
6363
} else {
6464
// Only output warnings for the built in whitelist as this clutters the output when the user
6565
// trying to execute a single test from the commandline.

0 commit comments

Comments
 (0)