Tests reported twice when using XUnit with TeamCity

Here’s a quickie for all you people running XUnit tests in a TeamCity build. TeamCity doesn’t directly support XUnit, so it takes a wee bit of effort to get things going. The way I decided to tackle the issue was to add the following bits to our test project build file:

<Target Name=CustomBuild DependsOnTargets=Build>
  <CallTarget Targets=Test Condition=$(TEAMCITY_PROJECT_NAME) != ” />
UsingTask AssemblyFile=..\packages\xunit.1.6.1\Tools\xunit.runner.msbuild.dll  TaskName=Xunit.Runner.MSBuild.xunit
<Target Name=Test>
  <xunit Assembly=$(TargetPath) NUnitXml=..\..\TestReport.xml />

The CustomBuild target depends on Build, so Build gets run in any case. This ensures that we always run the latest set of tests.

Then, if the build script detects TeamCity (by presence of the TEAMCITY_PROJECT_NAME variable), it runs the Test target, which outputs its results to TestReport.xml.

Having got this far, I added TestReport.xml to our TeamCity configuration, and things seemed to work nicely. Except that our tests got reported twice.

It took me a while to finally clue in to what was happening: TeamCity was already parsing the output of the XUnit test task, and having a separate test report was what caused the duplicates. This wasn’t immediately obvious to me, until we built a separate performance test bench and used console output to communicate its results to TeamCity (more on that in a future installment).

Long story short: TeamCity can already understand XUnit tests, it just doesn’t provide a way to run them.

ODP.NET application crash with DateTime parameters

I spent some time yesterday debugging a crashing console application – a proof of concept for a wrapper library I’m writing around an Oracle database. I had successfully read values from the DB – writing that code took all of five minutes – and then tried a MERGE statement.

(Side note: this is the first time I’ve written a merge statement. In fact, while I did know of MySQL’s “REPLACE INTO”, I had no idea that such a thing existed.)

I played around with the statement in TOAD for a while, to make sure it was correctly written, typed it into my editor, added parameter placeholders, added the arguments for the parameters and ran the application. It flashed on the screen and then disappeared.

Which was a bit weird, seeing as it ended with a Console.ReadLine() call. I re-ran the app just to make sure I didn’t accidentally press anything, and the same thing happened. Meanwhile, looking at the results on the TOAD side of things, the value was definitely updated.

I was a bit tired, so it took me a while to notice that the process exit code was 0x80000003 – nonzero, so some sort of error was being reported. Still, even asking the debugger to break on all Win32 errors yielded nothing. And between the statement being executed and the crash, ProcMon reported that all operations the application performed were successful.

I was too tired to make sense of it, so I went home and took a fresh set of eyes with me today. I began to narrow the issue down to a single parameter. At which point I began to get NRE’s instead of crashes. And the stack traces contained references to the special handling of DateTime parameters.

I was doing this:

command.Parameters.Add(new OracleParameter("curdate", DateTime.Now));

Figuring that DateTimes were a special case, I chose this constructor overload instead:

command.Parameters.Add(new OracleParameter("curdate", OracleDbType.Date,   DateTime.Now, ParameterDirection.Input));

After which I re-ran the app, and like magic, everything worked.

Now, realizing that Oracle has more than one way of representing the data contained in a System.DateTime, I understand how there might be a code path or two dedicated for the handling of DateTimes. What I don’t get is that it’s possible for the most common overload of the OracleParameter constructor to result in not an exception, but a full-on application crash.

Anyway, I hope this post saves someone else the trouble. Smile

Fixing broken tools

What sucks about open source is that when something breaks, there’s no guarantee that it will get fixed. What seriously rocks, though, is that you can do it yourself.

As an example of the latter, we’re using dotless for a project at work. I didn’t do much with it, apart from setting up the HttpHandler and letting our frontend developers loose on it. After a few days, though, they ran into an issue: editing an imported less file would not cause the root file to be evicted from the cache.

I figured this was an omission in the caching mechanism, and downloaded the sources from GitHub. When I finally got everything right so that debugging was an option, something weird happened – the path parsing seemed to break, and our includes no longer worked the way they used to.

I dove into the issue, thinking that I’d have to fix it in order to be able to debug the cache issue. When I finally understood enough of the codebase to write the correct tests and make them pass, I suddenly noticed that cache invalidation worked again.


Except, not so much when I finally figured it out. The path parsing bug led to imports like “/foo/bar” resolving to “foo/bar”. That in itself was bad enough, mind you, but since the cache code passed the same paths to the CacheDependency constructor, the net result was a cache dependency to a nonexistent file!

The docs for CacheDependency state the following:

“If the directory or file specified in the filename parameter is not found in the file system, it will be treated as missing. If the directory or file is missing when the object with the dependency is added to the Cache, the cached object will be removed from the Cache when the directory or file is created.”

That’s great, but in this particular case, I never want to watch for a file that might get created, so I would have been better served with an error. Smile

Anyway, after this little excursion in yak shaving it made sense that fixing path resolution also fixed the cache.

I contributed my changes as a fork on GitHub in the hopes that it will benefit others as well. Also, it would be nice if my changes were merged upstream, so I wouldn’t have to maintain my own fork. Smile with tongue out 

(I’m fairly sure I botched the Git operations somehow, though – I get that Git is awesome, but boy does it come with a learning curve.)

Anyhow, the important thing is that now our frontend developers don’t have to work with broken tools.

Including indirect, optional dependencies in builds

So I’m writing an application that uses NHibernate as its data access layer. I’m also writing a bunch of integration tasks, and a console driver for them. I’ve written the tests, and I’m ready to fire up the real thing from the console.

The first thing that happens is that my application dies. “Could not load file or assembly NHibernate.ByteCode.Castle”.

Well, bugger.

The weirdness starts when I look at my project’s dependencies. It doesn’t depend directly on NHibernate either, but the assembly gets copied to the output folder. So do most of NHibernate’s dependencies. But not this one. Why is that?

NHibernate comes with a set of byte code providers. While this may seem overkill, I get that people may already be using such a library, and forcing consumers to include yet another one is a no-no. So the dependency to a byte code provider is not a hard dependency. This means that in order to include it in our Visual Studio builds, we need to perform some trickery.

Fortunately, the trickery is rather simple. First, reference the chosen byte code provider in the project that has the NHibernate reference. At this point you may feel compelled to already test the results – don’t bother, they’ll be equally disappointing. Since the reference isn’t actually used anywhere, the build process will skip it.

Instead, what you need to do is add a compile-time reference – that is, directly use a class included in the assembly. Here’s what I did:

    #pragma warning disable 169
    // This reference ensures that we always get NHibernate.ByteCode.Castle.dll
    // as an indirect reference in other projects.
    private static readonly Type proxyFactory = typeof (NHibernate.ByteCode.Castle.ProxyFactory);
    #pragma warning restore 169

(The pragma does away with the compiler warning about an unused field.)

Of course, you can always accomplish the same thing with build scripts, this felt like a workable compromise. As a bonus, I don’t have to worry about this every time I reference this project.

My Biggest Career Move Yet

What a summer it has been. I took one of the most interesting vacation trips I’ve ever had – a three-week InterRail romp through Europe. We met interesting people, spent approximately 4 000 km on trains and drank a lot of beer. I don’t think I’ve spent that long without really thinking about work since I got started.

Getting really relaxed and out of work-mode was a really good idea. You see, before we left, I had made some plans, and I’ve been acting on the plans since I came back.

I’m switching jobs again. But this time both the reasons and the new job are a bit different: I’m setting up shop with Sami Poimala, Jouni Heikniemi and Riikka Heikniemi. My very own company, something I’ve been dreaming about for years now.

Exciting times!


So what’s the plan?

Well, since you asked, the long-term plan looks a lot like this:

Pinky and The Brain



However, that’s going to take some time to achieve, so the near-term plan looks more like this:

Will code HTML for food


In all seriousness, though, when you put the right people together, good things tend to happen. And I can’t think of a more fitting group of people to accompany me.

Chad Fowler says that when you play music, you should always strive to surround yourself with players that are better than you.

I think I just did. Smile

I’d like to thank all my soon-to-be-ex-coworkers at Sininen Meteoriitti. It’s been a brief, but fun ride together, and I won’t forget any of you any time soon. If you miss me terribly, you can always have someone make a pot of bad coffee and listen to some Eduard Khil!


Stay tuned for the next installment.

Post Haste

Meh, so I screwed up with Live Writer, and instead of using an earlier post as a template, I overwrote the old post. Fortunately Google Cache found the old post, but I had to do some updating to fix links that didn’t quite work, and it’s possible that RSS subscribers have been seeing random weirdness. 🙁

PowerShell quickie: expanding the properties of a variable inside a string

Here’s something that gave me a bit of trouble: I was attempting to run a script to upgrade a bunch of SharePoint solutions, and I wrote it like this:

dir –Recurse –Filter *.wsp | %{ stsadm –o upgradesolution –name $_ –filename $_.FullName –allowgacdeployment –local }

Now, that actually works, but since I hadn’t tested it before, I figured I’d echo the command out first, so I tried this:

dir –Recurse –Filter *.wsp | %{ echo "stsadm –o upgradesolution –name $_ –filename $_.FullName –allowgacdeployment –local" }

Which is all well and good, except it echos out something like the following:

stsadm –o upgradesolution -name Foo.wsp -filename Foo.wsp.FullName -allowgacdeployment -local

The reason this happens is that the string expansion in PowerShell has no way of knowing that I meant to expand the property instead of printing out the literal characters. Having figured this out, the next thing I tried was:

echo "${_.FullPath}"

Which doesn’t work either. Crap. I’m not familiar enough with the PowerShell syntax to explain why that is, but after a moment of pondering I finally figured out something that does work – expressions:

dir –Recurse –Filter *.wsp | %{ echo "stsadm –o upgradesolution –name $_ –filename $($_.FullName) –allowgacdeployment –local" }

The $() syntax allows us to evaluate any arbitrary expression, which is then inserted into the string. Yay!

Protocol-relative HTTP URLs

If you’re visiting a web page over an SSL encrypted connection, you might sometimes get an annoying “mixed content” warning. In essence, the browser is telling you that yes, the page itself was delivered over HTTPS, but other bits were not, and that may or may not mean that you’re in danger.

From the developer point of view, having to build every URL so that the protocol is taken into account can be tedious. It might equally well be the case that your framework of choice already handles this. If so, good for you.

However, there’s another escape hatch not known to most people: protocol-relative URLs. You write the url without the protocol and following colon, and the client will choose whichever protocol was used to retrieve the page, like so: //server:port/path/to/resource.html

Not sure how often this is actually necessary, but there you go. 🙂

Chapter 5: But I Can’t Because…

(This is part 5 in a series of posts where I document my progress through reading Becoming a Technical Leader: An Organic Problem-Solving Approach by Gerald Weinberg, answering the questions at the end of each chapter)

1. Do you know someone whose leadership style you particularly admire?

“Try to create a short career biography of this person, characterized in MOI terms. If possible, interview the person to check your perceptions.”

I can’t really name anyone for this exercise. This has been the primary reason I’ve been sitting on this blog post – the rest of it has been ready for quite a while now. I’ll just have to move on, unfortunately.

2. When was the last time you made a major change in your career?

“Which do you remember best, the factual details, or the feelings?”

I think the one and only major change so far has been leaving my first job after nearly seven years. I was primarily anxious, and afraid that I wouldn’t be good enough for the “real world”. Definitely feelings.

3. How did you react the last time someone you know well made a major career change?

“What else does that tell you about yourself?”

I was happy for that person, and a little envious. I felt like they were going somewhere, while I wasn’t. It’s mostly an issue of low self-esteem.

4. What change in your career have you made that you still don’t fully accept?

“don’t fully admit to others? to yourself? Can you now let go of it? Why?”

I’m not sure what this question is asking. A change that I wasn’t actually fully aware of, and hence don’t accept it, or a change that was forced on me? Either way, I don’t think I have any good examples.

5. Can you remember the first major decision point in your career?

“Can you still recall your feelings? Were you afraid to take the step? Was your fear justified? Was it worth it anyway?”

See question 2. Yes, I was afraid. Yes, I think the fear was justified, because I didn’t think we had ever assessed our actual competence level realistically. It was worth it, though. The next time I moved to a new job, I wasn’t anxious, and I think I made a point of looking at the right things when making the decision. I also got valuable experience from that job.

6. What are your choices for the next major decision point?

“What happens to your body as you contemplate each possible alternative? What messages pop into your mind?”

More or less direct responsibility. More or less of time in the spotlight. Less seems comfortable, but a bit boring. More makes me nervous and excited. The messages are along the lines of “do you want to make a difference or not?”

7. Have you ever been appointed Leader of anything?

“Did people begin to assume that you, as Leader, would now handle situations that they could perfectly well handle themselves? How did you deal with these situations? Were you so taken with your new status that you tried to handle them yourself, rather than delegating them where they belonged? How did your actions affect the group’s later reactions to you as Leader?”

Worse. I was so taken with my status, that I tried to handle things even when nobody asked me to! It lead to tension, bad decisions and me realizing that I wasn’t anything close to a real leader.

8. Next time you are appointed Leader of some group, keep a list of situations …

“… in which people assume that you as Leader will come up with the crucial ideas, but in which you exercise leadership by changing the environment so as to encourage them to do it. Keep going until you have at least ten items.”

Um, OK.

9. Have you ever felt when appointed Leader that you were essential to the group?

“What did the group do when you were not around? What did they do when you eventually left? Could there have been some sort of self-fulfilling prophecy in operation?”

See question 7.

10. For some group you work with, consider ho much of your influence in that group derives from your appointed position.

“How much comes from your idea power? How much from enhancing the idea power of others? Are you satisfied with this mix?”

Influence from appointed position is something I’d like to mostly do without. Most of my influence tends to come from my own actions and ideas. So far, I haven’t been very good at enabling others, except when paired with someone who is a good match with me.

11. Tomorrow morning change your traditional breakfast in some way.

“Notice if your day changes.”

I seemed to be a bit more focused in the morning, having a routine-breaking thing I needed to do.

12. For the next two weeks, change your breakfast each day according to some new idea each day

“(such as fewer or more calories, faster of slower preparation, more or less wholesome, more interaction with other people, less interaction with others, more appealing to look at, thirty minutes later, thirty minutes earlier, in a different place, using different utensils, hot instead of cold, cold instead of hot, more liquid, less liquid). Note what, if anything, is happening to you, and summarize the effect at the end of the two weeks.”

After a couple of days I settled into a mode, where I expected that my morning routine, while being routine, would change every day. I tried to avoid planning too much in advance, so I had to think on my feet to respond to the changes. I’d go as far as to say I was a bit more prepared for routine things to change in other areas of my day.

13. Tomorrow change the way you interact with some person you see frequently.

“Try to do it in such a way as to improve your interaction. Note the results.”

A tiny bit of conscious effort daily can have a huge positive impact on interaction, at least when both parties are naturally inclined to get along anyway. 🙂


Previously: Chapter 4: How Leaders Develop  Next up: Chapter 6: The Three Great Obstacles to Innovation

1 2 3 4 10