Fix threading issue in test