@@ -45,8 +45,7 @@ private[scalatest] class SuiteSortingReporter(dispatch: Reporter, val testSortin
45
45
}
46
46
}
47
47
48
- private val timer = new Timer
49
- private var timeoutTask : Option [TimeoutTask ] = None
48
+ private var timeoutTask : Option [(TimeoutTask , Timer )] = None
50
49
51
50
def doApply (event : Event ): Unit = {
52
51
synchronized {
@@ -177,6 +176,8 @@ private[scalatest] class SuiteSortingReporter(dispatch: Reporter, val testSortin
177
176
slotListBuf = fireReadySuiteEvents(slotListBuf.tail)
178
177
if (slotListBuf.size > 0 )
179
178
scheduleTimeoutTask()
179
+ else
180
+ cancelTimeoutTask()
180
181
}
181
182
}
182
183
}
@@ -283,23 +284,38 @@ private[scalatest] class SuiteSortingReporter(dispatch: Reporter, val testSortin
283
284
private def scheduleTimeoutTask (): Unit = {
284
285
val head = slotListBuf.head // Assumes waitingBuffer is non-empty. Put a require there to make that obvious.
285
286
timeoutTask match {
286
- case Some (task) =>
287
- if (head.suiteId != task.slot.suiteId) {
288
- task.cancel()
289
- timeoutTask = Some (new TimeoutTask (head)) // Replace the old with the new
290
- timer.schedule(timeoutTask.get, testSortingTimeout.millisPart)
287
+ case Some ((oldTask, oldTimer)) =>
288
+ if (head.suiteId != oldTask.slot.suiteId) {
289
+ oldTask.cancel()
290
+ oldTimer.cancel()
291
+ val (task, timer) = (new TimeoutTask (head), new Timer )
292
+ timeoutTask = Some ((task, timer)) // Replace the old with the new
293
+ timer.schedule(task, testSortingTimeout.millisPart)
291
294
}
292
295
case None =>
293
- timeoutTask = Some (new TimeoutTask (head)) // Just create a new one
294
- timer.schedule(timeoutTask.get, testSortingTimeout.millisPart)
296
+ val (task, timer) = (new TimeoutTask (head), new Timer )
297
+ timeoutTask = Some ((task, timer)) // Just create a new one
298
+ timer.schedule(task, testSortingTimeout.millisPart)
295
299
}
296
300
}
301
+
302
+ // Also happening inside synchronized block
303
+ private def cancelTimeoutTask (): Unit = {
304
+ timeoutTask match { // Waiting buffer is zero, so no timeout needed
305
+ case Some ((task, timer)) =>
306
+ task.cancel()
307
+ timer.cancel()
308
+ timeoutTask = None
309
+ case None =>
310
+ }
311
+ }
297
312
298
313
private def timeout (): Unit = {
299
314
synchronized {
300
315
if (slotListBuf.size > 0 ) {
301
316
val head = slotListBuf.head
302
- if (timeoutTask.get.slot.suiteId == head.suiteId) { // Probably a double check, or just in case there's race condition
317
+ val (task, _) = timeoutTask.get
318
+ if (task.slot.suiteId == head.suiteId) { // Probably a double check, or just in case there's race condition
303
319
val newSlot = head.copy(ready = true ) // Essentially, if time out, just say that one is ready. This test's events go out, and
304
320
slotListBuf.update(0 , newSlot)
305
321
}
0 commit comments