zopefoundation / zope.index

Indices for using with catalog like text, field, etc.
Other
10 stars 12 forks source link

Tests can randomly fail #22

Closed jamadden closed 5 years ago

jamadden commented 5 years ago

zope.index.text.ricecode.encode_deltas(a_list) returns a tuple (start, deltas). Usually deltas is an instance of zope.index.text.ricecode.RiceCode, but when len(a_list) == 1), deltas is a simple [].

This is an awkward API that causes problems: the inverse decode_deltas(start, deltas) method requires deltas to be a RiceCode and fails if you pass in an empty list.

This case can be seen in the zope.index's own testsuite, where test_random can fail non-deterministically.

Originally discovered in
https://github.com/zopefoundation/zope.index/pull/21#issuecomment-443264249

mgedmin commented 5 years ago

We can convert the non-deterministic failure to a deterministic failure by adding 1 to the list of sizes in test_random.

There are two ways of fixing the bug:

I'm not myself a user of zope.index.text.ricecode, so I don't know what's best.

mgedmin commented 5 years ago

Actually, we can't return empty RiceCode instances -- that makes decode_deltas fail with an IndexError: list index out of range.

It's starting to look like it'd be better to make decode_deltas handle empty deltas.