test/thread: Tweaking test and fixing bugs