Related to issue 38888: Failing SS Build
authorMartin Taal <martin.taal@openbravo.com>
Sat, 24 Nov 2018 15:33:13 +0100
changeset 7903 d5a0cfb1dc24
parent 7902 d02b36139e21
child 7904 33fcfe595e63
Related to issue 38888: Failing SS Build
Wait for all trans synced from central, wait for online mode
src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java
src-test/org/openbravo/test/mobile/retail/multiserver/selenium/terminals/WebPOSCentralOfflineTerminalHelper.java
src-test/org/openbravo/test/mobile/retail/multiserver/selenium/tests/offline/OfflineMSCentral003_CreateMultiorder.java
--- a/src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java	Fri Nov 23 09:39:04 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/multiserver/MultiserverUtils.java	Sat Nov 24 15:33:13 2018 +0100
@@ -112,6 +112,45 @@
 
   }
 
+  public static void waitForCentralOutgoingSynced(final long interval, final int tries) {
+    final String sqlOutgoing = "select COUNT(1) AS count from sym_outgoing_batch where node_id in (select mobile_server_key from obmobc_server_definition where servertype = 'MAIN') and status not in ('OK', 'IG')";
+
+    new OBWait(interval, (int) tries) {
+
+      @Override
+      protected boolean until(final int currentIteration) {
+        final ArrayList<Boolean> isServerSynchronized = new ArrayList<Boolean>();
+        isServerSynchronized.add(false);
+        new DatabaseHelperSelect() {
+          @Override
+          protected void yieldResultSet(final ResultSet rs) throws SQLException {
+            final Long count = rs.getLong("count");
+            final boolean isSynchronized = count == 0L;
+            if (!isSynchronized) {
+              TestLogger
+                  .getLogger()
+                  .info(
+                      String
+                          .format(
+                              "Waiting for symetricds to synchronize %s. Outgoing INSERT, UPDATE or DELETE: %s",
+                              ServerType.CENTRAL, count));
+            }
+
+            isServerSynchronized.set(0, isSynchronized);
+          }
+        }.execute(sqlOutgoing, 1, ServerType.CENTRAL);
+        return isServerSynchronized.get(0);
+      }
+
+      @Override
+      protected void timeout() {
+        throw new TimeoutException(String.format(
+                    "The central server has not send the data to the store after %s iterations and %s interval seconds",
+            tries, interval / 1000));
+      }
+    };
+  }
+
   public static void activateSynchronizedMode(final ServerType server) {
     TestLogger.getLogger().info("Activating Syncronized mode");
     final String sql = String
--- a/src-test/org/openbravo/test/mobile/retail/multiserver/selenium/terminals/WebPOSCentralOfflineTerminalHelper.java	Fri Nov 23 09:39:04 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/multiserver/selenium/terminals/WebPOSCentralOfflineTerminalHelper.java	Sat Nov 24 15:33:13 2018 +0100
@@ -26,8 +26,10 @@
 import org.openbravo.test.mobile.core.utils.OBConstants;
 import org.openbravo.test.mobile.core.utils.OBOfflineUtils;
 import org.openbravo.test.mobile.core.utils.OBUtils;
+import org.openbravo.test.mobile.core.utils.OBWait;
 import org.openbravo.test.mobile.core.utils.TestLogger;
 import org.openbravo.test.mobile.retail.mobilecore.selenium.TestIdConstructor;
+import org.openbravo.test.mobile.retail.mobilecore.utils.RetailUtils;
 import org.openbravo.test.mobile.retail.multiserver.MultiserverOfflineUtils;
 import org.openbravo.test.mobile.retail.multiserver.MultiserverUtils;
 import org.openbravo.test.mobile.retail.multiserver.selenium.TestIdMultiserver;
@@ -56,6 +58,8 @@
 
     TestLogger.getLogger().info("Force transitioning to offline");
 
+    MultiserverUtils.waitForCentralOutgoingSynced(5000, 20);
+
     // switch between modes that forces request
     // works for high volume mode, but not for normal mode
     tap(TestIdMultiserver.BUTTON_SCAN);
@@ -135,4 +139,19 @@
     }
   }
 
+  protected void waitForOnline(final long waitInterval, final int maxTries) {
+    new OBWait(waitInterval, maxTries) {
+      @Override
+      protected boolean until(final int currentIteration) {
+        Boolean isOnline = RetailUtils.isOnline();
+        return isOnline;
+      }
+
+      @Override
+      protected void timeout() {
+        throw new RuntimeException("Has pass " + (waitInterval * maxTries)
+            + " ms after go online, but pos is still not connected to erp.");
+      }
+    };
+  }
 }
--- a/src-test/org/openbravo/test/mobile/retail/multiserver/selenium/tests/offline/OfflineMSCentral003_CreateMultiorder.java	Fri Nov 23 09:39:04 2018 +0100
+++ b/src-test/org/openbravo/test/mobile/retail/multiserver/selenium/tests/offline/OfflineMSCentral003_CreateMultiorder.java	Sat Nov 24 15:33:13 2018 +0100
@@ -7,7 +7,6 @@
 import java.sql.SQLException;
 
 import org.junit.Test;
-import org.openbravo.test.mobile.core.utils.OBUtils;
 import org.openbravo.test.mobile.retail.mobilecore.annotations.TestClassAnnotations;
 import org.openbravo.test.mobile.retail.mobilecore.database.DatabaseHelperSelect;
 import org.openbravo.test.mobile.retail.mobilecore.javascript.BackboneHelper;
@@ -58,14 +57,11 @@
     tap(TestIdPack.BUTTON_SEARCHPRODUCT_BASECAMPLANTERN);
     verify(TestIdPack.LABEL_TOTALTOPAY, totalToPay2);
 
-    // small wait as it seems that menu is not clicked
-    OBUtils.pause(5000);
+    waitForOnline(2000, 60);
 
     // pay open tickets
     tap(TestIdPack.BUTTON_MENU);
-    OBUtils.pause(500);
     tap(TestIdPack.BUTTON_MENU_PAYOPENTICKETS);
-    OBUtils.pause(500);
     write(TestIdPack.FIELD_SEARCH_MULTIORDERS_TEXT, "VBS100");
     tap(TestIdPack.BUTTON_POPUP_OPENTICKETS_SEARCH);
     verifyHighVolumeTime(TestIdPack.BUTTON_POPUP_OPENTICKETS_SEARCH);