At line 79, it waits
while ( (numRacks < 2) || (curReplicas < REPLICATION_FACTOR) || (neededReplicationSize > 0))
But at line 95 it asserts
assertTrue(curReplicas == REPLICATION_FACTOR)
I believe that under the circumstances of the test, curReplicas will in fact be REPLICATION_FACTOR + 1, transiently. Changed the "while" to wait for the desired equality, i.e.,
while (curReplicas != REPLICATION_FACTOR).
Also changed the wait from infinite to a 20sec timeout with useful status output on failure.
Similar code in the other test case under TestBlocksWithNotEnoughRacks does not have the same problem, but still changed the wait from infinite to bounded.
Finally, added additional log messages useful for debugging if future problems.