Backport test-build from the master branch.

This is mostly the same with the exception of the socket engine
code being removed as the 2.0 socket engine switching interface
is absolutely terrible.