Best practice for unit tests that rely on internet access?

Alexander Clouter alex at digriz.org.uk
Tue May 3 22:39:17 BST 2011


David Cantrell <david at cantrell.org.uk> wrote:
> 
>> b) Only run the tests if specifically set by AUTHOR_TEST or something,
>> otherwise mock the server? (I dislike this.. means few good tests run
>> for users)
>> c) Try to test if there's a working connection, and silently skip the
>> tests if not? (Risks skipping tests if the connect fails for other
>> reasons than no outbound HTTP allowed)
> 
> You could always check whether outbound HTTP is allowed by connecting to
> somewhere entirely different.  Try penthouse or thepiratebay -
> somewhere which is highly unlikely to have been explicitly whitelisted,
> so is a good test of whether Generic Web Stuff can be expected to work.
> 
<network-monkey^Wsysadmin-hat> *winces* </network-monkey^Wsysadmin-hat>

I consider it 'unfriendly' to call on the resources of others for things 
that do not benefit them and also if (for example) 
penthouse/thepiratebay are down/unreachable (no such thing as "100% 
Internet access")/depreated/expired/changed/filtered/etc then your, 
possibly no longer actively maintained, module will fail.

It's the kind of thing that can lead to nasty side effects such as:

http://en.wikipedia.org/wiki/NTP_server_misuse_and_abuse

Assuming that the end user would probably only be installing the module 
in an environment where egress HTTP is permitted, I would be keen to 
encourage:
 * prime a localhost (remember ip6-localhost too!) HTTP mock service;
	remember that you might need to bind above port 1023/tcp
 * for such environments, hunt and use (http|ftp|https|all)_proxy 
	environment variables[1][2][4]
 * some sysadmin's (myself included) might permit port 80+443/tcp 
	direct, but if you want HTTP above 1023/tcp, you must use the 
	proxy...your module might want to bear this in mind
 * only communicate with the HTTP service your module is designed to 
	talk to (if it is not a generic HTTP client)
 * seek permission *first* from the sysadmin of any site you might want 
	to use as an HTTP 'probe' if you are determined to go down this 
	route.  You probably would not like it if I told all my friends 
	to constantly send ICMP Echo traffic at your DSL link to test 
	connectivity ;)

Cheers

[1] if they are present, it arguably is safe to assume things will work
[2] WPAD[3] is another approach to discover proxy servers, but to be 
	honest, if the local sysadmin is *only* providing you with 
	this as a proxy information option, then you have the right to 
	beat them around...it's the law
[3] http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol#Requirements
[4] this of course overlooks environments where SOCKS5 application 
	proxies rule the land; something I understand Auntie is keen on.

-- 
Alexander Clouter
.sigmonster says: What PROGRAM are they watching?



More information about the london.pm mailing list