tests: Reduce race condition between tests and log message recording