Made unittest safer towards race conditions.