2 ms·
I was dealing with a similar bug yesterday. I was using Python (Pyramid/SQLAlchemy/PostgreSQL) and had an integration test that was failing about 80% of the tim
by LyndsySimon 8y ago
I was dealing with a similar bug yesterday. I was using Python (Pyramid/SQLAlchemy/PostgreSQL) and had an integration test that was failing about 80% of the time, but would never fail when I stepped through the test code.
I ended up pairing with another developer, who rewrote the test from scratch and didn't have the issue. I think I know what the problem was, though - the test code called the route in question on one line, then the next line retrieved an object that was modified during the request. The line after that asserted that an attribute of that object had been changed. Most of the time, it hadn't changed; sometimes it had. To make matters work, any time the file was modified it seemed to work once or twice then begin failing again.
I'm 99% sure what was happening is that by the time the object retrieval happened in the test code, PostgreSQL hadn't fully committed the changes to the DB that were made during the request and the object returned was unmodified. Why was that happening? No idea. I suspect it was something to do with connection pooling or the way we were using gevent monkeypatching elsewhere, even though the tests themselves weren't using gevent.
Things like this are both the most frustrating and most fulfilling part of development :)