Skip to content

Commit

Permalink
Merge pull request #1259 from luizvaz/develop
Browse files Browse the repository at this point in the history
Fixed a issue with messages getting missed by wait.send method.
  • Loading branch information
ptrthomas authored Aug 18, 2020
2 parents a570297 + 802a004 commit 9a3d926
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected DevToolsDriver(DriverOptions options, Command command, String webSocke
logger = options.driverLogger;
this.options = options;
this.command = command;
this.wait = new DevToolsWait(options);
this.wait = new DevToolsWait(this, options);
int pos = webSocketUrl.lastIndexOf('/');
rootFrameId = webSocketUrl.substring(pos + 1);
logger.debug("root frame id: {}", rootFrameId);
Expand Down Expand Up @@ -150,12 +150,12 @@ public void send(DevToolsMessage dtm) {
}

public DevToolsMessage sendAndWait(DevToolsMessage dtm, Predicate<DevToolsMessage> condition) {
send(dtm);
boolean wasSubmit = submit;
if (condition == null && submit) {
submit = false;
condition = DevToolsWait.ALL_FRAMES_LOADED;
}
//Do stuff inside wait to avoid missing messages
DevToolsMessage result = wait.send(dtm, condition);
if (result == null && !wasSubmit) {
throw new RuntimeException("failed to get reply for: " + dtm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
public class DevToolsWait {

private final DriverOptions options;
private final DevToolsDriver driver;

private DevToolsMessage lastSent;
private Predicate<DevToolsMessage> condition;
Expand Down Expand Up @@ -73,7 +74,8 @@ public static Predicate<DevToolsMessage> forEvent(String name) {
return m -> name.equals(m.getMethod());
}

public DevToolsWait(DriverOptions options) {
public DevToolsWait(DevToolsDriver driver, DriverOptions options) {
this.driver = driver;
this.options = options;
logger = options.driverLogger;
}
Expand All @@ -97,6 +99,7 @@ public DevToolsMessage send(DevToolsMessage dtm, Predicate<DevToolsMessage> cond
synchronized (this) {
logger.trace(">> wait: {}", dtm);
try {
driver.send(dtm);
wait(timeout);
} catch (InterruptedException e) {
logger.error("interrupted: {} wait: {}", e.getMessage(), dtm);
Expand Down

0 comments on commit 9a3d926

Please sign in to comment.