Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3801#discussion_r22449487
  
    --- Diff: 
streaming/src/test/scala/org/apache/spark/streaming/TestSuiteBase.scala ---
    @@ -104,6 +106,77 @@ class TestOutputStreamWithPartitions[T: 
ClassTag](parent: DStream[T],
     }
     
     /**
    + * This is an interface that can be used to block until certain events 
occur, such as
    + * the start/completion of batches.  This is much less brittle than 
waiting on wall-clock time.
    + * Internally, this is implemented using a StreamingListener.  
Constructing a new instance of this
    + * class automatically registers a StreamingListener on the given 
StreamingContext.
    + */
    +class StreamingTestWaiter(ssc: StreamingContext) {
    +
    +  // All access to this state should be guarded by 
`StreamingTestWaiter.this.synchronized`
    +  private var numCompletedBatches = 0
    +  private var numStartedBatches = 0
    +
    +  private val listener = new StreamingListener {
    +    override def onBatchStarted(batchStarted: 
StreamingListenerBatchStarted): Unit =
    +      StreamingTestWaiter.this.synchronized {
    +        numStartedBatches += 1
    +        StreamingTestWaiter.this.notifyAll()
    +      }
    +    override def onBatchCompleted(batchCompleted: 
StreamingListenerBatchCompleted): Unit =
    +      StreamingTestWaiter.this.synchronized {
    +        numCompletedBatches += 1
    +        StreamingTestWaiter.this.notifyAll()
    +      }
    +  }
    +  ssc.addStreamingListener(listener)
    +
    +  def getNumCompletedBatches: Int = this.synchronized {
    +    numCompletedBatches
    +  }
    +
    +  def getNumStartedBatches: Int = this.synchronized {
    +    numStartedBatches
    +  }
    +
    +  /**
    +   * Block until the number of completed batches reaches the given 
threshold.
    +   */
    +  def waitForTotalBatchesCompleted(
    --- End diff --
    
    Actually, even this might be overkill: I can just use vanilla `eventually` 
since we're still blocking on a condition to occur and not relying on 
real-clock time; I guess using `wait` instead of `sleep` is just an 
optimization that might save a small amount of test time, but it's not related 
to flakiness (the goal of this PR).  Therefore, I'll just remove all of this in 
favor of `eventually` since then I'll benefit from ScalaTest's nice assertion 
macros.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to