TRUNK-4212: Fix race conditions that were causing this test to fail on systems under heavy CPU load.

Speed up the test by using CountDownLatch instead of arbitrary
Thread.sleep() delays.

Fix database unique identifier issues by removing hardcoded ids and saving
tasks before scheduling to generate unique IDs.