TDD Anti-Patterns

I Like this.  Have seen most of them (and probably been guilty of a few a while ago…)

I suggested a couple of others…

How about the ‘Stealth Bomber’. This is probably an extreme extension of the Hidden Dependency. I’ve seen a few tests that would simply ‘never’ fail when run interactively or debugged, or during a full test run in the day. When a supposed ‘fix’ was implemented it would even fool the developer into feeling pleased with themselves by passing for a day or two before bombing again in an overnight run. The logic wouldn’t show anything untoward, and it continued to bomb every few days without warning or trace of ‘why’. More than likely a group of no-no’s of execution sequence-dependent, date/time-dependent, database-dependent, context-dependent etc.

There’s probably another variation – maybe the ‘Blue Moon’. A test that’s specifically dependent on the current date, and fails as a result of things like public holidays, leap years, weekends, 5 week months etc. This is again most likely guilty of not setting up its own data.

Scheduled Shutdown and Wake Up (on LAN) – Part 2

After the first post I’ve been doing a bit of experimenting with my work machine (new) and also at home (old).  We’re all grown ups here so I’m not going to include many screen shots.  Hibernate seems the best option to me as it gives you the most options.  Maintain your state and when you power on, you’re back to a ‘locked’ logon, meaning that even if you decide not to do an automatic wakeup (or your system simply doesn’t support it), then your boot up time’s likely to be less than a minute in any case – so who cares!

I wanted that extra bit of convenience, so I’ve got a scheduled hibernate and wakeup now working at work and at home.

As a side note, I love keyboard shortcuts, and so here’s a list of shortcuts to Control Panel dialogs.

The procedure for hibernation is the same for all machines, but the wakeup will vary from full support to no support…


  1. Enable Hibernation through Power Options dialog in control panel (Hibernate Tab). Start–> Run –> powerconfig.cpl
  2. If you have 2gb of RAM or more download a Microsoft HotFix from here and install.  Hibernation won’t work without it.
  3. Open Device Manager (Start –> Run–>devmgmt.msc) and open the properties of the Network adapter you want to use to control the wake up
  4. Check the ‘Allow this device to bring the computer out of standby’ box (Power Management Tab)
  5. Ensure ‘Wake Up Capabilities’ (Advanced Tab) is not set to disabled or none.  Each network adapter will have different capabilities.  The work machine has (Both, Magic Packet, None, Wake up Frame).  The option was already set to ‘both’ so I didn’t make any change.
  6. Create a new scheduled task (Start –> Run –> control schedtasks) called Hibernate with the following in the Run box…
    C:\WINDOWS\system32\rundll32.exe  powrprof.dll,SetSuspendState Hibernate

  7. Go to the Settings Tab, and configure the idle time (if necessary).  I configured the following (which seems to work OK):

    Most of the risk of losing stuff is mitigated by doing a hibernate over a full shut down in any case.  I haven’t tested whether the idle time recognises non-UI processes – e.g. say I’m encoding video.  I guess I’ll find out one day…
  8. Schedule the task to run at a time when you’re comfortable to switch off every day (taking any overnight processes like backups or defrags into account – maybe bring those forward) – remember ‘any’ time your computer is powered off is a good thing.  I’ve got the work machine set to go off at 18:00, and the home machine to go off at 23:00.


The work machine (Dell Precision 690 Xeon 3.2ghz, 2gb RAM) responds quite happily to the following :

  1. Create another scheduled task called ‘Wake up’ (or something equally innovative), and put literally ‘any’ command line in.  I just fudge the following as it will exit once finished…
    C:\WINDOWS\SYSTEM32\cmd.exe /C dir (This just opens a command shell – runs a dir then exits)
  2. Schedule this to run ‘just before’ you think you’re going to need it every day.  I get in early so the work machine comes on at 07:25 and I don’t need the home machine until 19:00 after the kids are in bed.

The home machine (can’t remember the spec – but it’s older – circa 2004) – the case is actually a ‘lot’ older, (but recycling is another thread) won’t respond at all to the wake up scheduled task, and so based on the C# code posted previously I created a LANWakeup console app (there’s plenty of other ones kicking around) to send a magic packet to the MAC Address of my home Network Adapter.  I’ll update the post to include this… 

This is then scheduled on my ‘other’ home machine at 19:00, and this works fine.  The only problem of course is that I then can’t turn ‘both’ machines off overnight as something needs to be ‘on’ in order to send the wakeup.  The other home machine is also older than the one I’ve got hibernating and it would need to be ‘remotely’ woken up too.


If you try your hibernate task and it comes straight back on, then it’s responding to other network traffic (which happens with some machines apparently – the home one experienced this but not the work one).  In this case do the following:

  1. Go back into Device Manager and the ‘Power Management’ properties of your Network Adapter, then check ‘Only allow management stations to bring the computer out of standby’.  This seems to help the adapter ignore general broadcast traffic and only respond to specific wake up requests (worked for me anyway)

New machines (last 3-4 years) are almost certain to have wakeup capability in some shape or form.  The newer the machine, the more likely it’s preconfigured in the BIOS.  If wakeup isn’t working in any way then you’ll need to go into the BIOS on startup (Del / F2 / Ins – etc) and look for Power Management options.  The previous post had a link on BIOS setup.  If you’re dealing with more ‘vintage’ kit then you’ll have to resort to the on-off button to wake the machine up, but I kindof like the idea of that, and may ditch the auto-wakeup in time, as it’s a bit lazy really!

Becoming slightly more environmentally friendly – Scheduled shutdown and Wake up

I leave computers on at home (bad boy), but I have slightly environmental sensibilities, so I’ve been wondering how I can best retain the convenience of having machines available when I want them, but also conserve energy when they’re not being used (assuming of course they’re not ‘doing’ anything overnight).

If you’ve got the disk space then it seems the best (easiest) option is probably a scheduled ‘hibernate’ (if idle for n minutes) at night, followed by another ‘wake up’ task in the morning (with ‘wake the computer to run this task’).  The wake up task could do an auto logon if you need.  Hibernate actually powers off (Standby doesn’t), but effectively writes your system state to disk (using approx same disk space as total RAM).  You need to go into power options first to ‘enable’ hibernate.

This article explains how to schedule a hibernate – just change the psshutdown options to -h instead of -d. I also don’t care if there’s a logged on user.  (Actually scratch that – as I found the following command will happily do a hibernate without any other tool – much nicer…. ) 

C:\WINDOWS\system32\rundll32.exe  powrprof.dll,SetSuspendState Hibernate

I also found this, talking about issues with hibernate.

Waking up is a little bit more troublesome and is unlikely to work unless you enable your network adapter to respond to wakeup calls.  This goes into a bit more detail on that.

If you want to go further and just ‘shut down’ rather than hibernate, then step 1 would be the same – just change the psshutdown options again to -k

If you’re completely shut down, you’ll need some sort of Wake On LAN capability (something I’ve never really bothered with before), and I found this code that’ll do nicely as a console app.

I haven’t decided which way to go yet, as I prefer the idea of a complete shutdown without the need for disk space to write system state to disk, but then you need another machine that’s ‘on’ to wake the shut-down machine back up (potentially defeating the purpose?).  The first (hibernate) option is self-contained within the one machine, and uses a built-in facility to wake the machine up using the system clock.  I also do a backup each night, so I’ll maybe bring that forward and schedule a hibernate of all machines.  I’ll be interested to see the difference in the electricity usage.  I might post a more full procedure when I’m happy everything’s working for me…


Google Gadget for Connex Melbourne Service Status

I was playing around today and knocked up a quick Google Gadget (for use with iGoogle) for people in Melbourne to monitor the status of the train services delivered by Connex.  This is available on the Connex site, but conveniently sits in its own frame and so was easy to port to a ‘gadget’.

No real rocket science (and the gadget editor’s a bit buggy) – but I love the concept…

Click Add to Google to add it to your iGoogle Page

I’ve posted it to the ‘directory’ so it will hopefully be accessible from the main ‘gadget search’ soon…

Australian BOM Weather Gadget on iGoogle

I’d been looking for a ‘proper’ Australian Weather gadget for iGoogle, as the default one (presumably US-based) is rather inaccurate at times.  The following are links to two Gadgets linking to BOM (Bureau of Meteorology) data… (5 day weather forecast) (Radar Picture)