Fix unit test thread problem