Welcome to the Monastery | |
PerlMonks |
I cancelled my Christmas vacationby pg (Canon) |
on Dec 22, 2003 at 01:04 UTC ( [id://316281]=perlmeditation: print w/replies, xml ) | Need Help?? |
What is your feeling, if your application behaves randomly, today passes all testing and tomorrow fails every single test case? especailly the application is in production already. I cancelled my vacation, or to be more precise, my company asked me to cancel my vacation, and carry it to next year. So there is a big deal. One month ago, some one made a small change to our schedule system (not the schedule system to schedule applications, but the schedule system to schedule trucks and the delivery to our stores), it was all good for one whole month, but at the beginning of last week, two orders were mis-scheduled, and goods got delivered to stores two days later than it should be. That is indeed a big problem, considering that Xmas is the biggest time for my company. So people started to worry and started to re-test in our UAT (User Acceptance testing) system. Then the most strange thing happened. All test cases failed, everyone had a long face, especially those who did the UAT testing before the change was moved to production system, as they clearly remembered that all test cases passed at that time. So everyone freaked out...some people started to look into the code. People continued to test and investigate the code, but on the second day, all test cases passed, with no code change. I heard of that, and cautioned everyone that that was no way a good news, but a very very bad news, as to pass the testing no longer meant pass, and simply meant nothing, as it was random. It continued into the third day, and again, all test cases passed. They even repeated the production problem in UAT, and it passed! Everybody confused, and all kinds of theories started to fly...the mysterious randomness of the system... Now as a lucky guy, I was caught in the middle of this. That system is written in c, and I am the c guru, at least to others' perception. I started with a little hope, and I actually cautioned everyone not to put too much bet on me, as three people had already banging their heads on this code for three days, and there was absolutely no progress. Once I started to look at it, I had to agree with others, that the code was really ugly. Nobody in this company wrote it, it was bought from a bankrupted UK company. I wished that they indeed bankrupted before they had sold the garbage to other people. 10 long hours passed, I still had no idea why it behaved randomly. During that 10 hours, I chatted with the programmer who did the changes, and all the changes were just fine to me. At the 11th hour, suddenly a set of qsort and bsearch (they were not touched, but...) caught my eyes. I stared at them for a good 30 seconds, and told myself, yes, that was it! The qsort and bsearch used a set of fields as the unique key. With the recent change, that key lost its uniqueness. To maintain the uniqueness, a new field needs to be added to form the key. With non-unique key, the result from bsearch is simply unpredictable, and randomly returns the first row it hits with the non-unique key. The result can be changed base on the position of records and the length of the table being searched. A small 10-line code change will resolve this entire mystery. I still cannot go back to my vacation, as Monday I have to implement this tiny change, and support the UAT testing. Everybody wants it before Xmas and new year! Merry Christmas and Happy New Year to every fellow monk!!!
Back to
Meditations
|
|