How to Diagnose a Test Failure on TeamCity

Have you ever had that unit test that works locally, but fails on team city. Turns out you can debug them and find out that it isn’t team city’s fault.

Failing Team City Builds

You run the test locally, pass, run them on team city, fail. Alright, time to get serious, 1, pull the TeamCity artifact down locally, 2, run MSTest from command line like TeamCity does, 3, start debugging. Most unit test frameworks throw exceptions when a test fails, great way to debug into the test.

Make sure you have an artifact from TeamCity or you can’t pull down the test. Well, unless you are an admin on the box.

TeamCity Test Artifact

TeamCity Download Artifact

Visual Studio Attach to Process

Open up Visual Studio Command Prompt for VS2015.

[code]
mstest /testcontainer:MyTests.dll
[/code]

Next, attach to the MSTest process QUICKLY. MSTest launches QTAgent32.exe for running the actual unit tests but it won’t stop to wait for you.

Attach To Process QTAgent32.exe

In the end, it turned out another test ran first, and our second tests couldn’t set a private static readonly because of its if null check.

[code langauge=”csharp”]
private static readonly List<int> Codes = new List<int>();
[/code]

Benchmarking MVC6 Beta 8

I have always been curious how fast MVC can be, and a previous article (http://blog.bitdiff.com/2012/06/performance-comparison-iis-75-and-iis-8.html) detailed the Web API  speeds with IIS 7.5 to IIS 8 along with self-hosted options. So I spun up a MVC 6 web  app with Beta-8 and used the Apache BenchMark to test it out. Running a i7-3740QM CPU with Windows 7.

My controller contained only this,

[csharp]

[Route("api/[controller]")]
public class ValuesController : Controller
{
// GET: api/values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}

[/csharp]

I fired up Apache Benchmark using the command below.

[code]ab -n 1000 -c 2 http://localhost:5000/api/Values [/code]

3.064MS! It beats out the 17.818 from Windows 8 Self Host and I am running Windows 7! This is a localhost call, so adding in SSL or a network would likely increase this. but it helps if it starts really low first.

The first “Time per request” is for each request * concurrent request number. The second “Time per request” is the actual individual requests. Wonderfully explained at this ServerFault question http://serverfault.com/questions/274252/apache-ab-please-explain-the-output

mvc6-beta8-batch1

For giggles, I pumped it up to 10,000 concurrent requests, I also tried 5,000 concurrent requests and got the same ~7ms response time.

mvc6-beta8-crazyconcurrent

So basically MVC6 is FAST! VS2015 diagnostic session for those who wanted to take a peek. I might have had around 100 chrome tabs open when running this benchmark.

 

 

vs2015 diagnostic session

 

Entity Framework MSSQL Sequence Numbers

I had an application where I wanted to have a sequence key that spanned multiple tables. Mainly to provide better logging support, so the log search would be “Find Object X” instead of “Find object X with type Y”. Then add in namespacing and the logs start to get wide, IE “Find Object 12 with type Company.Product.Service.Model.ModelName” repeated hundreds of times.

Step 1, make sure your object in Entity Framework is set to a StoreGeneratedPattern of “None”. (Right click table, select properties, go to the property window)

Entity Framework Properties

Change your Entities partial class to include this override to save changes.

[gist id=”400bb4513848ef85bf3a” synhi=true lang=”csharp”]

And done!

 

Failed to start shard

I have a project that uses ElasticSearch for searching and all the goodness that it has. When I test a new technology, I like to break it a few times.  Like adding a bunch of data, hitting the stop button on the service or killing the task in task manager.

So I did this with ElasticSearch, and I received this error message.

failed to recover shard]; nested: ElasticsearchIllegalArgumentException[No version type match

Everywhere that I read included some details about how the disk filled up, or was low on space.

Capture

 

Simple solution, flush the index. ElasticSearch has an internal and on disk transaction log.  Being used to SQL’s ACID based consistency, you can’t shutdown the service without ill-effects. 8-7-2014 10-58-01 AM

 

More details on the flush command and how to access it from the API versus the HEAD plugin, http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-flush.html