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

Default caching (documentation?) issues #132

Closed
timdiggins opened this issue Jun 10, 2019 · 7 comments · Fixed by #133
Closed

Default caching (documentation?) issues #132

timdiggins opened this issue Jun 10, 2019 · 7 comments · Fixed by #133
Labels
bug doc Documentation

Comments

@timdiggins
Copy link

Summary

The docs (https://github.com/titusfortner/webdrivers#caching-drivers) suggest that the default caching is set to 24 hours (86,400 seconds) however from my experience and what I can see in the code, the default is only set for the rake tasks.

see

Webdrivers.cache_time = ENV.fetch('WD_CACHE_TIME', 86_400)
for example

vs

(@cache_time || ENV['WD_CACHE_TIME']).to_i

I think either the docs need to change ("the default is set for rake tasks...") or the code does ( (@cache_time || ENV.fetch('WD_CACHE_TIME', 86_400)).to_i
or possibly just dedupe the default config into one place)

There is one more documentation issue with caching: if you are not pinning the version you are using, then even with caching it will do a check for the latest version every time, which is surprising. (This is because correct_binary? needs to find latest_version when required_version == EMPTY_VERSION).

@titusfortner
Copy link
Owner

You're right this default value didn't get updated for the 4.0 release.

As for checking latest version, we still need to do that. If your browser updated, the cached driver version might not be compatible. We only skip that if you hard code a specific version, which we don't recommend unless you have a locked down testing platform.

@timdiggins
Copy link
Author

As for checking latest version, we still need to do that. If your browser updated, the cached driver version might not be compatible. We only skip that if you hard code a specific version, which we don't recommend unless you have a locked down testing platform.

ah ok thanks that makes sense -- I was just surprised I needed to configure WebMock even though I had already installed the latest version by running the rake task within the cache window..

@kapoorlakshya
Copy link
Collaborator

Hi @timdiggins, can you please test the fix from master in your project and confirm that it works for you? Thanks!

@timdiggins
Copy link
Author

@kapoorlakshya debug output below (bold indicates non-duplicated lines AFAICT).

with released version:

2019-06-11 17:27:09 DEBUG Webdrivers Checking current version
2019-06-11 17:27:09 DEBUG Webdrivers /Users/tim/.webdrivers/chromedriver is already downloaded
2019-06-11 17:27:09 DEBUG Webdrivers making System call: /Users/tim/.webdrivers/chromedriver --version
2019-06-11 17:27:09 DEBUG Webdrivers Current version of /Users/tim/.webdrivers/chromedriver is ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40})

2019-06-11 17:27:09 DEBUG Webdrivers making System call: //Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
2019-06-11 17:27:09 DEBUG Webdrivers Browser version: Google Chrome 75.0.3770.80
2019-06-11 17:27:09 DEBUG Webdrivers making System call: //Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
2019-06-11 17:27:09 DEBUG Webdrivers Browser version: Google Chrome 75.0.3770.80
2019-06-11 17:27:09 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_75.0.3770
2019-06-11 17:27:09 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>

2019-06-11 17:27:09 DEBUG Webdrivers Latest version available: 75.0.3770.8
2019-06-11 17:27:09 DEBUG Webdrivers A working webdriver version is already on the system

with master:

2019-06-11 17:27:53 DEBUG Webdrivers Checking current version
2019-06-11 17:27:53 DEBUG Webdrivers /Users/tim/.webdrivers/chromedriver is already downloaded
2019-06-11 17:27:53 DEBUG Webdrivers making System call: /Users/tim/.webdrivers/chromedriver --version
2019-06-11 17:27:54 DEBUG Webdrivers Current version of /Users/tim/.webdrivers/chromedriver is ChromeDriver 75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40})

2019-06-11 17:27:54 DEBUG Webdrivers making System call: //Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
2019-06-11 17:27:54 DEBUG Webdrivers Browser version: Google Chrome 75.0.3770.80
2019-06-11 17:27:54 DEBUG Webdrivers Latest version available: 75.0.3770.8
2019-06-11 17:27:54 DEBUG Webdrivers A working webdriver version is already on the system

So this looks good to me, though it seems to contradict with earlier statement above: (but I'm still not convinced by this because, on reflection, it seems to me that if you don't use the cache time to prevent checking for latest version, I'm not sure what cache time is used for...)

As for checking latest version, we still need to do that. If your browser updated, the cached driver version might not be compatible. We only skip that if you hard code a specific version, which we don't recommend unless you have a locked down testing platform.

@kapoorlakshya
Copy link
Collaborator

@timdiggins The cache time is respected as long as a chromedriver binary exists AND the major versions of Chrome and chromedriver match. Once the major versions stop matching, the cache time is ignored and an update check is forced to get the latest compatible chromedriver for Chrome. For example, when your Chrome updates to v76 tomorrow, but your chromedriver is still at v75, the cache time will be ignored and webdrivers will force download chromedriver v76 to make sure you're using a compatible driver.

You can perform a short test to verify this if you want:

Webdrivers::Chromedriver.remove
Webdrivers::Chromedriver.required_version = '72.0.3626.7' # Any old version will work
Webdrivers::Chromedriver.update

Assuming you have Chrome v75, let's set cache time to 1 hour and trigger an update:

Webdrivers.logger.level = :debug
Webdrivers.cache_time = 3600
Webdrivers::Chromedriver.update

You should see the following lines in the log:

2019-06-11 15:04:35 DEBUG Webdrivers making System call: C:\Users\Lakshya Kapoor\.webdrivers\chromedriver.exe --version
2019-06-11 15:04:36 DEBUG Webdrivers Current version of C:\Users\Lakshya Kapoor\.webdrivers\chromedriver.exe is ChromeDriver 72.0.3626.7 (efcef9a3ecda02b2132af215116a03852d08b9cb)

# removed...

2019-06-11 15:04:38 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-11 15:04:38 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_75.0.3770
2019-06-11 15:04:39 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2019-06-11 15:04:39 DEBUG Webdrivers Latest version available: 75.0.3770.8

# ...and it downloads the latest v75

As you can see, the cache time was ignored and a network call was made to fetch a compatible driver version (v75) for Chrome. Now, if you want to test further, you rerun the test with cache time set to 1 hour and check the logs. You'll see that no network calls are made since we already have a compatible version.

2019-06-11 15:11:52 DEBUG Webdrivers Browser version: 75.0.3770.80
2019-06-11 15:11:52 DEBUG Webdrivers Latest version available: 75.0.3770.8
2019-06-11 15:11:52 DEBUG Webdrivers A working webdriver version is already on the system

Now, if you don't even want this to happen, you can pin the version and the gem will not make any network calls at all until you change the required version.

Hope this helps.

@kapoorlakshya
Copy link
Collaborator

kapoorlakshya commented Jun 11, 2019

I have documented this special case in the README for the v4.0.1 release.

EDIT: Fixed link.

@timdiggins
Copy link
Author

Thanks for superb explanation @kapoorlakshya -- very clear now.

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

Successfully merging a pull request may close this issue.

3 participants