We have a large and complex function that must be deterministic. This is one of the workhorses of our company and covers a large amount of code. This code often becomes non-deterministic due to the python dict iterator. This has happened many times, and it is very difficult to track and often not notice immediately. We would like to write an automated test to detect non-determinism, but I'm not sure how to do this.
We tried to run the function in a loop, and testing the results is always the same, but sometimes, although the function is not deterministic, the function will pass this test because of the arbitrary but somewhat sequential ordering of the dict iterator.
Is there a way to write an automated test to catch such an error?
Perhaps there is a way to crack a python dict so that iterators are random rather than arbitrary during this test? So repeated function calls will be more likely to diverge? This seems like a pretty complicated method, but I can't think of anything else.
EDIT:
We are currently using Python 2.7.
We have single tests of various submodules, however, they often do not exhibit non-determinism due to the arbitrary but consistent nature of the dictate order.
, , . {id: data}, , - python . , - , .