Fix for posible race conditions in tests

@tgoyne @finnschiermer