From 74fa96fb30f593e07f2c6ade18fa0b92e6230ec2 Mon Sep 17 00:00:00 2001 From: LuizVaz Date: Tue, 18 Aug 2020 00:31:31 -0300 Subject: [PATCH] Fixed a issue with messages getting missed by wait.send method. Caused by lastSent getting set late then reponse come out from websocket. --- .../main/java/com/intuit/karate/driver/DevToolsDriver.java | 4 ++-- .../src/main/java/com/intuit/karate/driver/DevToolsWait.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/karate-core/src/main/java/com/intuit/karate/driver/DevToolsDriver.java b/karate-core/src/main/java/com/intuit/karate/driver/DevToolsDriver.java index 3f7bdf1e0..5b7a23c78 100644 --- a/karate-core/src/main/java/com/intuit/karate/driver/DevToolsDriver.java +++ b/karate-core/src/main/java/com/intuit/karate/driver/DevToolsDriver.java @@ -150,13 +150,13 @@ public void send(DevToolsMessage dtm) { } public DevToolsMessage sendAndWait(DevToolsMessage dtm, Predicate condition) { - send(dtm); boolean wasSubmit = submit; if (condition == null && submit) { submit = false; condition = DevToolsWait.ALL_FRAMES_LOADED; } - DevToolsMessage result = wait.send(dtm, condition); + //Do stuff inside this to avoid missing messages + DevToolsMessage result = wait.send(dtm, condition, this); if (result == null && !wasSubmit) { throw new RuntimeException("failed to get reply for: " + dtm); } diff --git a/karate-core/src/main/java/com/intuit/karate/driver/DevToolsWait.java b/karate-core/src/main/java/com/intuit/karate/driver/DevToolsWait.java index 0d78bbcb8..e92b48bf3 100644 --- a/karate-core/src/main/java/com/intuit/karate/driver/DevToolsWait.java +++ b/karate-core/src/main/java/com/intuit/karate/driver/DevToolsWait.java @@ -89,7 +89,7 @@ public void setCondition(Predicate condition) { this.condition = condition; } - public DevToolsMessage send(DevToolsMessage dtm, Predicate condition) { + public DevToolsMessage send(DevToolsMessage dtm, Predicate condition, DevToolsDriver dtd) { lastReceived = null; lastSent = dtm; this.condition = condition == null ? DEFAULT : condition; @@ -97,6 +97,7 @@ public DevToolsMessage send(DevToolsMessage dtm, Predicate cond synchronized (this) { logger.trace(">> wait: {}", dtm); try { + dtd.send(dtm); wait(timeout); } catch (InterruptedException e) { logger.error("interrupted: {} wait: {}", e.getMessage(), dtm);