Fix a threadsafety bug in unit tests.