Fix hang on test finish.
Add self-testing test.