Cucumber + Selenium + Machinist

Posted by Chris on November 02, 2009

This weekend I worked on setting up a Selenium test for Plus 3 Network using Cucumber. I’ve been using Machinist to create fixtures for my non-Selenium Cucumber scenarios. I wanted to continue using my Machinist blueprints that I had already setup so that my Selenium tests would use the same random data.

The issue I ran into was that ActiveRecord doesn’t actaully commit it’s changes to the database, it executes a rollback at the end of each scenario. This is an issue because Webrat/Selenium actaully creates a Mongrel instance and runs it’s tests against that which is a totally different transaction.

The workaround is quite simple, just turn off the transactions for your Selenium environment, use DatabaseCleaner to clean the database and generate your Machinist fixtures in a Before hook. You just need to set Cucumber::Rails::World.use_transactional_fixtures to false in your enhanced.rb and true in your plain.rb. For generating my Machinist fixtures I have a method called “machine_fixtures” (pretty catchy eh?) in my blueprints.rb file. Here is what it looks like:

And my enhanced.rb has the hooks for generating the fixtures using “machine_fixtures” and for cleaning the database.

And for good measure here is what the plain.rb looks like:

I’m assuming you setup your Cucumber/Selenium environment like this: http://wiki.github.com/aslakhellesoy/cucumber/setting-up-selenium. The instructions mention the whole transaction issue and using DatabaseCleaner to clean out the database but it didn’t quite hit me till I tried using the Machinist fixtures. Hopefully this will clear things up for some other Noob.

Nginx… Load Balancer… Reverse Proxy… Jack of all Trades

Posted by Chris on October 28, 2009

Lately Nginx has become my new best friend. It seems like every time I think “Hey I want to do …” Nginx is the solution. Recently I’ve setup a new “high availability” cluster for Plus 3 Network and needed a easy-to-configure load balancer to route the traffic between the web servers.

In previous architectures I’ve resorted to wrestling with Linux Virtual Server to handle this job. I was dreading having to go through that painful process again. So this time I searched the interweb and turned up this blog post which sparked the idea of using Nginx to solve this problem.

Along with the load balancing I also wanted to setup a reverse proxy for some of the dynamically created images on the site and cacheable content that we needed to move off the file system and into the database to share across each web server. Plus there were some other dynamically generated bits and pieces that I didn’t want slowing down the our web servers.

The load balancing/reverse proxy part in Nginx is pretty simple since Nginx has the HTTP Proxy module built in. The configuration was similar to setting up the upstream servers for a Mongrel/Thin installation except it would just round robin the requests to the web servers instead the local instances. It also allows you to setup different proxy schemes for different locations… ie. cache the avatars that are stored in the database or the Google map thumbnails.

One additional nugget of goodness I found was the ability to scale and crop images on the fly using Nginx’s Image Filter module. This completely removes the burden from the Rails servers and makes creating square avatar images a snap.

Form a performance standpoint, it blows a Rails only solution out of the ballpark. During my perf tests I was getting about 700 - 900 request/sec on the avatar images (which is comparable to a static image on the site). The Rails server can serve the source image at around 190 request/sec with caching enabled. Not bad for an image that is stored in the database, served via Rails and dynamically scaled/cropped on the fly.

Here is my configuration for the load balancer. It has all the usual goodies that a good reverse proxy needs… dynamic image scaling, expires tags, gzipping, the works! If you have any question feel free to put them in the comments.

It’s never easy (when it’s hot!)

Posted by Chris on September 28, 2009

Yesterday Patrick and I decided to meet up for a “lazy” ride at Skeggs. We have both been putting in the miles lately and we thought it might be nice to just get together for a easy ride where we are not slaves to some schedule like a typical dawn patrol ride.

The plan was to just take it easy on the climbs and have fun. And I think we could have accomplished that had we not ridden at Skeggs. It’s all climbing there. Nothing but climbing (well some descending but you spend more time climbing they you do descending). By the end we where both spent… well I was more spent then Patrick of course since I started slurring my speech and lost a bit of my coordination.

Plus it was hot as hell out! When I say hot I mean “drink 100oz of water and ask for more” kind of hot. The kind where when you get into the shower after the ride and you’re drier then when you stepped in (I know that doesn’t make any sense what so ever but it’s my damn blog and my logic prevails here!).

The kind of hot where you think, “you know I could probably squeeze another 50oz bladder in my pack”. And that’s how ideas are born… After I ran out of water, I fantasized about having a frozen 50oz bladder in my pack that would conveniently melt enough to quench my hydration needs by the time I downed the 1st 100oz.

Of course this would compliment the “freeze half your bladder trick” I learned riding in AZ in the summer. So the next time I  have a ridiculous idea of riding in super hot weather I’m going to employ this new spectacular super bladder idea.

BTW… Patrick and I raised $1.68 for our causes on Plus 3 Network. Check out our rides:

Patrick’s ride and my ride

I was attacked! 2

Posted by Chris on August 21, 2009

Yesterday on my commute back from a meeting at the Yahoo! Great America office I was attacked by a vicious Wasp! I was riding along minding my own business when out of now where this little bastard jumped me.

I could tell this thing had no honor nor did it abide by any rules of fighting. It went straight for my eyes trying with all it’s might to blind me. It knew just how to do it too. It flew right under my glasses and started to mount it’s assault like a group of angry marines avenging the death of one of their fallen brothers (not that I’ve even see a group of angry marines avenge their bother’s death but I image it’s quite a sight).

As you can see from the evidence below it got a good piece of me but I think I managed to crushed it’s stupid little wings when I batted it out from under my glasses. Wasps have officially made the list of the Axis of Evil Creatures (right along with their suicidal buddies, the squirrels)!

The result of the wasp attack!

The Dawn Patrol 1

Posted by Chris on August 20, 2009

One of the hardest things about being a husband, father, young (is 35 still young?) professional and cyclist is finding time to squeeze in a good mountain bike ride. I found the only way to accomplish this is to get up at the butt crack of dawn and hit the trails.

Even harder is to sucker some other poor souls into meeting you for an early morning ride. But when you throw in the promise of some prime “ranger-free” singletrack and breath taking views it makes it a bit easier.

With those two benefits, I’ve finally suckered Patrick and Joe into joining me for my morning Dawn Patrol Ride at Saratoga Gap. We all agree it’s really hard to pry yourself out of a comfortable bed but when we hit the spot in the photo above, it’s totally worth it.

Being the first to ride a trail in the morning is pretty satisfying, it’s comforting to know that you can rail that twisty section without worrying about another rider coming the other way. The only real risk is hitting wild life loitering in the middle of the trail (what are they thinking? Get out of the way Bambi! Jeeez!)

Climbing out

Yesterday while climbing out of Peter’s Loop, I mentioned to Joe and Patrick that I was considering putting forth my entry for the “Specialized Trail Crew” contest. I explained how I thought it would be interesting to focus my blog a bit more and open up a wider forum for discussing my three passions: riding, advocacy and technology. They unanimously thought it was a cool idea, Pweew!… just the validation I needed.

One interesting angle would be to see how much money I could raise for my cause on Plus 3 Network using the bike Specialized would graciously loan to me for a year. As an added bonus I’ve even plotted a route from my new apartment to work that is off-road almost the entire way.

Keep your fingers crossed… Here are the stats from yesterday’s ride.


View Larger Map

(I actually rode 13 miles today but I forgot to hit the start button on my GPS till we got to Peter’s Loop… Doah!)

Update: Patrick just sent me this photo… ha!

Trail repairs