Make compaction test code more robust