views:

360

answers:

4

Hi, how i can configure the Test Project of visual studio to use all CPU's core.

When i run the test i can see on my performance indicator that only one core is being used (100%) and the rest 7 cores is being unused.

I have inside the Test Project a Load Test that is calling a UNitary Test.

I had set 200 users to call a single method. But i need to use all Cores.

A: 

The chances are that your test code is all single-threaded. Unit Tests are run sequentially, so unless the code in each test is multi-threaded, it will only run in one thread.

Be carefull that running tests in multiple threads can have adverse consequences, unit tests should only test the unit, and if that is multi-threaded, then the test should be single-threaded.

ck
+2  A: 

See the accepted answer here. Summary: you need Visual Studio Team System Test Load Agent to do this.

FouZ
A: 

You have to do work in multiple threads. Try this:

class Program
{
    static bool isRunning = true;

    static void Main(string[] args)
    {
        BackgroundWorker bw1 = new BackgroundWorker();
        BackgroundWorker bw2 = new BackgroundWorker();

        bw1.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw2.DoWork += delegate(object sender, DoWorkEventArgs e)
        { while (isRunning) { } };

        bw1.RunWorkerAsync();
        bw2.RunWorkerAsync();

        Console.ReadLine();
        isRunning = false;

    }
}

You can increase the number of background workers depending on how many cores you have (this example maxes out my dual core computer). You can put your code after you run the workers, and then stop them by changing the value of isRunning.

SLC
My unit test can be executed on a single core. What i need is that Visual Studio use all my cores to connect the Users the unit test.
Vanilla
+2  A: 

Hi, Dennis, according to MSDN (http://msdn.microsoft.com/en-us/library/ms243155.aspx):

"Adding a Visual Studio Load Test Virtual User Pack 2010 in a nontest controller scenario has the added benefit of unlocking all machine processors for use. Without a Visual Studio Load Test Virtual User Pack 2010, your local machine can use only the first processor. After you have added a Visual Studio Load Test Virtual User Pack 2010, load tests can use all processors on the machine when they run."

So there's no way to unlock your additional cores if you don't have the user pack license.

Regards,

Я!©ђ!Є ©Я∆ZΨ

richie_crazy57