Refactor test.

The test_callback function, I hope, is general enough to handle many
tests, possibly including the thread and non-failure cases as well.