Attached is a patch to fix this failure.
I looked into this, and looks like the reason behind this is that the following sequence:
add 5 documents
delete 1 document
Somehow leads to two segments being created, one with four documents, and the other with 1. I can't imagine the soft commit frequency being hit or something like that, but may be some other test parameter deep in Lucene is triggering this – I haven't been able to figure out why.
Since this test doesn't aim to verify Lucene behaviour anyway, I modified the test case to account for multiple segments..