Introduce the mock module to improve unit tests.

There are a few socket corner-cases that are incredibly hard to reproduce in a
unit test suite, so we use mock to trigger the exceptions instead.
Bump unit tests, fix two serious wee buglets discovered.