by encoderer · 11y ago · 0 comments
Then I was coding on the train home one night and in the tube my hotspot lost connection. Then I happened to notice... with wifi off the tests ran 10x quicker. Pull out netstat.... I see http requests to akamai essentially as each test setUp() is run. It's SSL so I only see a hostname, not the full path, and they just look like this, but the hostname is dynamic: a23-34-132-181.deploy.static.akamaitechnologies.com
I spent 30 mins reviewing our code, grepping my code and packages directories, and stepping thru in a debugger. No luck.
The worst was having a Map keyed on URLs in Java -- turns out URL.equals() and URL.hashCode() do DNS lookups... Easiest 50% test speedup ever!
The other suggestions -- using a SSL proxy -- has been my plan of attack.
- start a test from the IDE,
- wait a second or so,
- manually pause all threads,
- look at the stacks of the threads.
Might take two or three attempts, but likely should learn you a lot. Alternatively, use a real profiler to find the call(s) that take lots of time. strace -e trace=network ./run_my_unit_testsUse java.net.Uri, or e.g. the equivalent from Jersey or whatever your local framework/HTTP client/... brings with it.
Joshua Bloch used this as an example in one of the brilliant Java Puzzler video series with the net advise of don't depend on non-local state for equality.
[0]: https://mitmproxy.org/, https://mitmproxy.org/doc/ssl.html
[0]: http://nedbatchelder.com/blog/201503/finding_temp_file_creat...
https://jimshaver.net/2015/02/11/decrypting-tls-browser-traf...