Testing for Fun and Profit

Fun:
When Brian mentioned the sale on Learning Perl and Mastering Perl, I went and purchased two of each. Presumably one for me and one for my girlfriend. I haven't read mine but instead gave it to my younger brother who decided to learn Perl. I've been helping him almost daily with the material and the homework.

Yesterday I presented him the idea of tests and showed him Test::More. You see, until now he's been manually running each exercise in the book and comparing the output with what the book says it should be.

Instead he can now write what the book expects it to be as a test and run the code, then just see if it's "ok" or "not ok". Much simpler. He likes it very much.

Profit:
Today I had to propagate MySQL optimizations to a rather long list of servers. The problem is that each of these servers has specific replication-related preferences such as the server_id. Patching won't help because there are possible (which is admin-speak for "definite") differences between the files, they are of different versions and so on.

Instead of going over every file and trying to push the changes in manually, I wrote a script that goes over the my.cnf, extracts the personal variables, puts them in a file and then adds an !include in the my.cnf to read that file.

However, I'm very cautious at $work (or I like to think I am), and things are very volatile here so I wrote 32 tests (spanning across 4 files) that the script runs in various stages along the change. This assures me that before the script dissects the files I have a backup of the my.cnf somewhere, I know I have the correct variables I want to extract and that they are enabled and activated, etc. etc. Basically making sure there are no surprises.

All in all, this is a serious time saver because I don't have to go server by server manually and check things or make the changes themselves. The tests are run, I see the result and I press [enter] to authorize the script running. Beautiful!

Leave a comment

About Sawyer X

user-pic Gots to do the bloggingz