test: fix race condition - build thread and teardown