Higher level IPC abstraction (fixes 238)

This is mostly refactoring.

Fixes #238.
:question: Probably worth splitting this into a separate non-`test_` module (since it is being imported by other test code).