Fix data race in test writer