Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very long delay when running C# unit test in VS2015

I have a very long delay (about 1 minute! even more) when running unit test in VS2015. When running even a single test, I see the progress bar in the top of the "Test Explorer", it flows for about a minute, and then I get the test result. The reported test runtime is as expected - very small, few milliseconds.

My question is - how can I debug this? How can I see what is going on in this minute before the test actually starts to run?

like image 801
duduamar Avatar asked Jan 31 '16 14:01

duduamar


People also ask

Does C have a delay function?

Delay in C: delay function is used to suspend execution of a program for a particular time. Declaration: void delay(unsigned int); Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds).

How does delay work in C?

The delay() function is built upon a C library function called clock(). The clock() function returns a time value in clock ticks, which is based on the processor's speed. The value returned is of the clock_t variable type. You can use subsequent reads of the clock() function to determine elapsed time.

Why is C++ slow?

Some reasons are: 1) C++ grammar is more complex than C# or Java and takes more time to parse. 2) (More important) C++ compiler produces machine code and does all optimizations during compilation. C# and Java go just half way and leave these steps to JIT.

How do you use delay function?

The way the delay() function works is pretty simple. It accepts a single integer (or number) argument. This number represents the time (measured in milliseconds). The program should wait until moving on to the next line of code when it encounters this function.


1 Answers

A minute is quite a long time for nothing to be happening. There is a lot of startup processing that has to happen before any tests are run (all of the assemblies and their dependencies need to be loaded for example). This hit is generally the same if you're running a single test or running all of the tests in your suite.

If you look in the "Tests" output window, you'll get a better idea of what's actually going on and the actual amount of time taken to run the tests. For example on mine, running one test shows a similar overhead to running 49 tests..

========== Run test finished: 1 run (0:00:01.0416253) ==========

========== Run test finished: 49 run (0:00:01.9156121) ==========

There are various things that can slow down assembly loading, such as static constructors. I would tend to start off by creating a fresh test project with no dependencies to verify that it doesn't exhibit the same long delay issue so that you know it's not just your machine. Then I'd add in the dependencies of your existing test project, one dependency at a time to see if adding a particular dependency triggers the delay... Then I would look at that project to see if there's anything going on, such as static constructors that attempt to connect to a database / establish network connections.

It may also be worth trying to debug your tests, but making sure that you've got Break When Exceptions are thrown turned on (if it is something like a failed database connection that's causing the slow down there's a good chance an exception might be thrown as part of that process).

like image 187
forsvarir Avatar answered Oct 04 '22 15:10

forsvarir