Fix test through avoiding racing conditions