You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cb...@apache.org on 2017/10/19 08:44:08 UTC
[incubator-openwhisk] branch master updated: Add batching time to
BatcherTests. (#2861)
This is an automated email from the ASF dual-hosted git repository.
cbickel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 8dd6250 Add batching time to BatcherTests. (#2861)
8dd6250 is described below
commit 8dd6250fa98aa2d85635a506e207bdffdab2c4f0
Author: Markus Thömmes <ma...@me.com>
AuthorDate: Thu Oct 19 10:44:06 2017 +0200
Add batching time to BatcherTests. (#2861)
In an environment with no parallelism some assertion do not hold water which makes this test non-deterministic. Adding a bit of a delay between batching calls allows the batch to build up.
---
.../whisk/core/database/test/BatcherTests.scala | 26 +++++++++++++++-------
1 file changed, 18 insertions(+), 8 deletions(-)
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 51f54ba..a2eac6f 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)
}
--
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].