Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a separate proxy for WDA commands without session ID #395

Merged
merged 5 commits into from
Mar 15, 2017

Conversation

mykola-mokhnach
Copy link
Contributor

Some WDA commands don't require session ID to be set. Such commands can be executed even if the application under test is not active. This PR adds support for such endpoints to WDA driver

Copy link
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good way to handle future no session commands from WDA. Nice thinking, @mykola-mokhnach. I had one question otherwise LGTM.

this.setupProxy(sessionId);
return this.webDriverAgentUrl;
}

log.info('Launching WebDriverAgent on the device');

this.setupNoSessionProxy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we set up the noSessionProxy twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use this.url instance variable inside setupNoSessionProxy method and it is mandatory, that this variable is properly set before we call it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed before line 165 (where we initialize the other proxy)? If not, I would vote for just putting the no-session proxy initialization into setupProxy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately it is not possible to combine proxies init into single method, since noSessionProxy is used for getting driver status to detect whether WDA is running after xcodebuild has been executed. And the jwproxy can only be initialised after sessionId is known (which is known only after session init)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We pass sessionId into the launch method. The setupProxy method is also called before the xcodebuild command is run.

@@ -7,7 +7,7 @@ const GET_STATUS_COMMAND = 'getStatus';

let helpers = {}, extensions = {};

helpers.proxyCommand = async function (endpoint, method, body) {
helpers.proxyCommand = async function (endpoint, method, body, isSessionCommand=true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we've documented this appropriately in our style guide, but we put spaces around = in default parameter values like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, will do

throw new Error(`Received non-zero status code from WDA server: '${res.status}'`);
const proxyTimeout = this.noSessionProxy.timeout;
try {
this.noSessionProxy.timeout = this.wdaLaunchTimeout < 5000 ? this.wdaLaunchTimeout / 2 : 5000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit cryptic, maybe it deserves a comment? why would we halve the proxy timeout if the launch timeout is less than 5s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I'm not sure about the actual timeout value here. Probably, it would be smart to set the timeout to the lowest value possible, so it does not delay retries?

Copy link
Member

@jlipps jlipps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes LGTM now! think isaac should also review

Copy link
Contributor

@imurchie imurchie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. A couple of things to look into.

this.setupProxy(sessionId);
return this.webDriverAgentUrl;
}

log.info('Launching WebDriverAgent on the device');

this.setupNoSessionProxy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed before line 165 (where we initialize the other proxy)? If not, I would vote for just putting the no-session proxy initialization into setupProxy.

@@ -25,6 +24,37 @@ const WDA_AGENT_PORT = 8100;
const WDA_BASE_URL = 'http://localhost';
const BUILD_TEST_DELAY = 1000;


class NoSessionProxy extends JWProxy {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this be in its own file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, but got circular dependency error as a result :(
I don't know the other way how to get rid of it except of putting the class together with main WDA class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird. I just tried and had no problems.

Copy link
Contributor Author

@mykola-mokhnach mykola-mokhnach Mar 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be happy if you could show me how to implement it properly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

many thanks. Shall I also imp[ort util module from appium-support there?

Will it work if I import it like this, assuming I save this file as "no-session-proxy.js" into same folder

import { NoSessionProxy } from "./no-session-proxy"

?

Copy link
Contributor

@imurchie imurchie Mar 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, you'll need the util module from appium-support.

If it is in the same directory you should be able to import with either of the two:

import NoSessionProxy from './no-session-proxy';
import { NoSessionProxy } from './no-session-proxy';

@mykola-mokhnach
Copy link
Contributor Author

yep, it works! thanks @imurchie
-1

Copy link
Contributor

@imurchie imurchie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@imurchie
Copy link
Contributor

The CI failure is fixed in a different PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants