Archive for January, 2008

When Good Programs Go Spamming

January 26th, 2008 by ScottK | No Comments | Filed in Programming

Whether it’s unit testing or behavior driven I like testing, and usually go overboard on such. I’m also a big stickler on handling exceptions as well. I just completed a fix to a very small program that turned out to be a huge spam engine because the original programmer had neither testing or exception handling and yet a large amount of spam complaints were coming in and this program was the final end point.

This program is in production and as I evaluated the complaints and faults it really blew me away that spam was being sent at all. The program itself was written in C# and used as a windows service. So whenever it faulted it was restarted by the services a minute later. That’s all well and good as far as keeping it running on faults, but why was it sending spam.

All it had to do was query a database and grab a group list. For each of the lists it then queried the database to find all the emails to send. So what we had here was two loop conditions. For each lists grab the associated emails and for each email send. If a fault in either of the two killing the program should have not send the wrong email to a list. Right?

Well in practice this did not happen. Even on the fault of the email retrieval the program did continue to run for the group list with the previous queries emails; if even for a few emails before crashing. This became spam and this is where the complaints came from.

Testing aside this is why handling exceptions is extremely important to the sanity of our programs. If a fault occurs during the initial retrieval of the group list occurs it is safe to let the program crash as the windows service will restart it. However during the associated emails retrieval portion I added a try/catch portion. If the database returned the emails then continue processing as normal, otherwise “continue” (and log) the next group integration. Simple as that!

What was the result of this seemingly simple fix? Not only did cross sending emails to the wrong group list stop, but the program no longer faulted out every time it ran.

While fault tolerance is a testable method (insert your method of choice) it really is a programming path of itself and that what I am showing here. A test could have said “given that the database timed out the program should continue normally”, the exception handling for this test can change the entire logic or operation of the program. Proper exception planning along with program operation planning greatly enhances its usefulness.

I’m still in shock and awe that even when a simple program like this crashes it still somehow continued to operate, albeit incorrectly. Oh well it’s fixed now.

Fail! cakePHP 1.2 model testing with associations

January 20th, 2008 by ScottK | No Comments | Filed in cakePHP

I love to unit test! All the way down to my JavaScript libraries you’ll find a unit test. While some may argue that Behavior Driven Development is better I find that that TDD not only affords me more robust bug free code but also ensures that I am not going off track during development. So with cakePHP 1.2 beta and simpleTest we get a unit test framework for making sure that the code we write is tested prior to production.

Very Cool as that is one judgement I use to determine if the language or framework I am working with will amount to anything, i.e. can it be tested. cakePHP can be tested with SimpleTest and you can load fixtures to make sure your tests are correctly setup for what you need to

However….

With the introductions of associations in cakePHP it fails miserably.  Given that I have a model for a blog post I can write and use all the tests that I need to make sure that it performs exactly as I need it to do and handle all the foreseen exceptions. That was really cool until I added the comment model. The post model has many comments and the comment model belongs to a post. That’s where the problems begin.

The resulting unit test then began to throw exceptions in the tests where looking for test_suite_post_id in the comment table as opposed to post_id. What I mean is that in the comment model that belonged to a single post one field was post_id which was the foriegn key to the post so the model associations would work. In the testing environment however the tests where looking for a field called test_suite_post_id which didn’t exist.

I did find that if you import the database field representation with records => true you would not throw the errors and exceptions. Seriously though it’s using live data from your production database and you have no way to fine grain the exceptions to test your tests.

Certainly one could argue that the fixtures could implement the strange behavior as such but because  the comment fixture test would only load the fixtures for the comment model and not multiple models, I would hope that post_comment fixtures file wouldn’t be necessary (I didn’t even try this) during the setup of the comment test. In this structure there would be a lot of files for testing one model as large sites development.

With cakePHP 1.2 beta we have been presented with a lot of goodness. Testing for associative models still needs some improvement however. I’m not sure if it’s cakePHP or the simpleTest platform for the failure but non-associative testing works just fine.

Win and Awesome! BlogRush

January 19th, 2008 by ScottK | No Comments | Filed in News

It’s rare that a web service comes out that makes me go OOOOH!, but BlogRush has done just that. I mean from my point of view as someone who makes widgets and plugins for various platforms how many tracking services do we need? What’s the bottom line relavence of the information displayed? Does it work?

I subscribed to BlogRush around October of of 2007 to check them out and that was during version 1.x. Not really interested in the service but their pitch of delivering visitors to my site by placing their widget in my code was something I wanted to see if they delivered. Not having the time to check up with BlogRush I never really verified any information until today. I can say I’m impressed with the new version!

When I logged in I was greeted with a dashboard I don’t remember seeing, yet found that they have syndicating my feeds to other member sites. I got a display of how many readers clicked through the member sites to read my posts and with BlogRush’s algorythms a display of how important the post was to the reader. That’s powerful information to me. Based upon the BlogRush stats I can see that readers love my cakePHP posts!!

As to how BlogRush works is by a crediting system. OK I’ll admit that I’m a bit lost on this but on the top level I earn 1 credit for everytime the BlogRush widget is loaded on my page. After that I get confused. However these credits mean my posts are displayed on other BlogRush members sites and are providing click thru’s.

Check out BlogRush. It’s the only site I’ve found that not only provides me with visitors as advertised but also provides me with invaluable information on just what topics are important to my readers. Additionally they are still working on new features as well as creating a brand new site to help bring more visitors. Win and Awesome on the net!