Finding the performance problem

time to read 9 min | 1792 words

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.