Replace the semaphore test with a condition lock

This allows stepped execution of the test and doesn’t introduce a racy test to test a race condition