Ayende @ Rahien

Unnatural acts on source code

Finding the performance problem

Background: I was pairing with another dev to do Watin tests for a page, we have code similar to this:

[Test]

public void CanAddNoteToPolicy()

{

       ie.Link("AddNote").Click();

       ie.TextField("NoteText").TypeText("This is the comment text");

       ie.Button("SaveNewNote").Click();

       Thread.Sleep(500);//wait for the ajax call to return

       AssertPageContainsText("This is the comment text");

}

The test failed, and when we investigated why, we found that it was because the call took ~1.3 seconds to complete. This is on a local machine, so I was naturally worried about it. I increased the time and the test passed, but it was still worrying that it took so long. It basically was filling an entity from the user input and saving it to the database.

I went over the code, and couldn't really find something wrong with it, but it consistently took way more time than it should. I was about to open up a profiler when I remembered...

/// <summary>

/// Notify the web service that we created a new note

/// If completes, the web service accepted the new note and will

/// process it in due time.

/// If failed, the web service didn't accept the note, probably need

/// to fail the transaction in this case.

/// </summary>

public virtual void BeginNoteInsertion(Note note)

{

       //Oren: we don't have the web service yet, so we just simulate the

       //duration of avg call at the moment

       Thread.Sleep(1000); 

}

That was some mighty head smack, I tell you that.

Comments

Rik Hemsley
03/07/2007 09:56 PM by
Rik Hemsley

You just lost my respect for writing that Thread.Sleep(1000) then regained it when I remembered you'd just admitted it to the world.

Ayende Rahien
03/07/2007 10:05 PM by
Ayende Rahien

The reasoning behind it is sound (I think), I want to simulate a real latency for now, since I would be replacing this with a web service call, and I don't want all the tests that makes assumptions about the length of the call to break when I do.

I should also mention that it is in a class called: FakeInserter

shawn hinsey
03/08/2007 09:00 AM by
shawn hinsey

Sounds like a great use case for that expiring hack exception you wrote about!

Comments have been closed on this topic.