20
m144
3y

So today, again, I discovered the importance of unitests.
I was solving this performance issue, in which we had a few update actions for multiple entities in mongo, but it took FOREVER to complete, even when I unified it into one bulkWrite command.
Since the unified write did improve performance slightly, and we wanted to move on, we decided to let this bug go.
So there I was committing my changes when I got a rejection from the pre-commit hook since I didn't have enough unitests coverage.
Ok, let's start writing some unitests.
Some unitests also needed to test the bulk write. So there I was comparing expected with actual result, and suddenly I got a huge facepalm.
Apparently some rogue for loop iterated all entities again for each entity that needed update. So instead of getting one update per entity, I got N identical update commands per each of the N entities 🤦‍♂️
Needless to say, fixing this fixed the performance bug entirely.
Thank you unitests and pre-commit hooks!

Comments
  • 4
    So the unittest didn't actually catch the issue, it's just the commit hook that forced you to look at your code again..
  • 2
    @Nihil75 technically, yes. But the unitests pinpointed the actual bug. It took me a long time to understand why I was getting so many dupes.
Add Comment