You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/10/19 08:44:10 UTC

[GitHub] cbickel closed pull request #2861: Add batching time to BatcherTests.

cbickel closed pull request #2861: Add batching time to BatcherTests.
URL: https://github.com/apache/incubator-openwhisk/pull/2861
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/src/test/scala/whisk/core/database/test/BatcherTests.scala b/tests/src/test/scala/whisk/core/database/test/BatcherTests.scala
index 51f54baa89..a2eac6f478 100644
--- a/tests/src/test/scala/whisk/core/database/test/BatcherTests.scala
+++ b/tests/src/test/scala/whisk/core/database/test/BatcherTests.scala
@@ -30,18 +30,24 @@ import whisk.utils.retry
 
 import scala.collection.mutable
 import scala.concurrent.duration._
-import scala.concurrent.{Await, ExecutionContext, Future, Promise}
+import scala.concurrent.{Await, Future, Promise}
 
 @RunWith(classOf[JUnitRunner])
 class BatcherTests extends FlatSpec with Matchers with WskActorSystem {
   implicit val materializer: ActorMaterializer = ActorMaterializer()
-  implicit val ec: ExecutionContext = actorSystem.dispatcher
 
   def await[V](f: Future[V]) = Await.result(f, 10.seconds)
 
   def between(start: Instant, end: Instant) =
     Duration.fromNanos(java.time.Duration.between(start, end).toNanos)
 
+  val promiseDelay = 100.milliseconds
+  def resolveDelayed(p: Promise[Unit], delay: FiniteDuration = promiseDelay) =
+    akka.pattern.after(delay, actorSystem.scheduler) {
+      p.success(())
+      Future.successful(())
+    }
+
   behavior of "Batcher"
 
   it should "batch based on batch size" in {
@@ -60,19 +66,23 @@ class BatcherTests extends FlatSpec with Matchers with WskActorSystem {
     val results = values.map(batcher.put)
 
     // First "batch"
-    retry(batchOperation.calls should have size 1, 100)
-    ps(0).success(())
+    retry(batchOperation.calls should have size 1, (promiseDelay.toMillis * 2).toInt)
     batchOperation.calls(0) should have size 1
 
+    // Allow batch to build up
+    resolveDelayed(ps(0))
+
     // Second batch
-    retry(batchOperation.calls should have size 2, 100)
-    ps(1).success(())
+    retry(batchOperation.calls should have size 2, (promiseDelay.toMillis * 2).toInt)
     batchOperation.calls(1) should have size 2
 
+    // Allow batch to build up
+    resolveDelayed(ps(1))
+
     // Third batch
-    retry(batchOperation.calls should have size 3, 100)
-    ps(2).success(())
+    retry(batchOperation.calls should have size 3, (promiseDelay.toMillis * 2).toInt)
     batchOperation.calls(2) should have size 2
+    ps(2).success(())
 
     await(Future.sequence(results)) shouldBe values.map(transform)
   }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services