@@ -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 =>
0 commit comments