Documentation

Documentation
V5 Documentation

NCrunch.Framework.UsesThreadsAttribute

NCrunch.Framework Attribute Introduced NCrunch v4.17

Purpose

This attribute is used to identify tests that require more than a single execution thread for their processing. When a test is declared as using more than one thread, the engine will reserve additional space for it in the processing queue. If there are not enough processing threads to execute the test configured for the local client or any connected grid nodes, the test will not be executed automatically by NCrunch.

Declaration In NCrunch.Framework.dll

namespace NCrunch.Framework
{
    public class UsesThreadsAttribute: Attribute
    {
        public UsesThreadsAttribute(int threads)
        {
            Threads = threads;
        }

        public int Threads { get; }
    }
}

You can declare this in your own code if you want NCrunch to use it - or otherwise reference the attribute from NCrunch.Framework.dll.

Usage example

public class MyFixture
{
    [UsesThreads(4)]
    [Test]
    public void MyTest()
    {
        ...
    }
}

Recommendations

This attribute can be used to balance the tests moving through NCrunch's test pipeline to prevent the local machine (and connected grid) from becoming overloaded. Not all tests are equal in terms of their resource consumption, and a large test that uses many threads can cause resource starvation on the system, causing other tests to time out.

When working on a large solution with many tests, it's recommended that you apply this attribute to any tests that are expected to consume more than a single thread during their execution. This will help to keep the background processing load at a more stable level, preventing intermittent timeouts.

This attribute can also be applied at fixture or assembly level, in which case it will be logically applied to all tests within the respective fixture or assembly.

Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download