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 2018/08/23 09:25:47 UTC

[GitHub] markusthoemmes commented on a change in pull request #3982: Make tests with CouchDB-views more stable.

markusthoemmes commented on a change in pull request #3982: Make tests with CouchDB-views more stable.
URL: https://github.com/apache/incubator-openwhisk/pull/3982#discussion_r212238995
 
 

 ##########
 File path: tests/src/test/scala/whisk/core/database/test/DbUtils.scala
 ##########
 @@ -103,51 +104,41 @@ trait DbUtils extends Assertions {
   def waitOnView[Au](db: ArtifactStore[Au], path: EntityPath, count: Int, view: View)(
     implicit context: ExecutionContext,
     transid: TransactionId,
-    timeout: Duration): Unit = waitOnViewImpl(db, path.asString, count, view)
+    timeout: Duration): Unit =
+    waitOnViewImpl(db, List(path.asString), List(path.asString, WhiskEntityQueries.TOP), count, view)
 
   /**
-   * Wait on a view to update with documents added to namespace. This uses retry above,
+   * Wait on a view to update with documents added(don't specify the namespace). This uses retry above,
    * where the step performs a direct db query to retrieve the view and check the count
    * matches the given value.
    */
-  private def waitOnViewImpl[Au](db: ArtifactStore[Au], key: String, count: Int, view: View)(
-    implicit context: ExecutionContext,
-    transid: TransactionId,
-    timeout: Duration): Unit = {
-    val success = retry(
-      () => {
-        val startKey = List(key)
-        val endKey = List(key, WhiskEntityQueries.TOP)
-        db.query(view.name, startKey, endKey, 0, 0, false, true, false, StaleParameter.No) map { l =>
-          if (l.length != count) {
-            throw RetryOp()
-          } else true
-        }
-      },
-      timeout)
-    assert(success.isSuccess, "wait aborted")
-  }
+  def waitOnView[Au](db: ArtifactStore[Au], count: Int, view: View)(implicit context: ExecutionContext,
+                                                                    transid: TransactionId,
+                                                                    timeout: Duration): Unit =
+    waitOnViewImpl(db, List.empty, List.empty, count, view)
 
   /**
-   * Wait on a view to update with documents added(don't specify the namespace). This uses retry above,
+   * Wait on a view to update with documents added to namespace. This uses retry above,
    * where the step performs a direct db query to retrieve the view and check the count
    * matches the given value.
    */
-  def waitOnView[Au](db: ArtifactStore[Au], count: Int, view: View)(implicit context: ExecutionContext,
-                                                                    transid: TransactionId,
-                                                                    timeout: Duration): Unit = {
-    val success = retry(
-      () => {
-        val startKey = List.empty
-        val endKey = List.empty
+  private def waitOnViewImpl[Au](
+    db: ArtifactStore[Au],
+    startKey: List[String],
+    endKey: List[String],
+    count: Int,
+    view: View)(implicit context: ExecutionContext, transid: TransactionId, timeout: Duration): Unit = {
+    // Query the view at least 5 times successfully, to handle inconsistency between several CouchDB-nodes.
+    (0 until 5).map { _ =>
 
 Review comment:
   Please factor the `5` into a constant.

----------------------------------------------------------------
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