Daily Usage Issues

Ensure test resource is initialized with parallel testing?

Started by GreenMoose on 4,038 views

[v3.17.0.2]

I have a test project where a static initialization requires a startup-initialization of a resource which then tests are using.

Is there a way to tell NCrunch to run this initialization "isolated" in the context of current test node ("local" or grid nodes)?

E.g. I have test1+2 requiring a test db to be set up, but these tests are allowed to be run in parallel and the test db is setup as part of a static construction, but this causes issues when both tests are starting simultaneously since they both run the initialization routine on (local).

Thanks.
ExclusivelyUsesAttribute can be used for this. Its scope is the machine (not the whole grid), so using this attribute would solve your problem. Though of course this would then prevent the tests from being run in parallel at all.

I would actually solve this in your test code by using a system-wide Mutex for the initialization code. Here's an example of how to do this.

Edited

Remco wrote:ExclusivelyUsesAttribute can be used for this. Its scope is the machine (not the whole grid), so using this attribute would solve your problem.

Suppose I have gridnode1, which is used by runner console1 and console2 that may run simultaneously. Will ExclusivelyUsesAttribute ensure that console2 waits for console1 to stop using the resource, if they are both using gridnode1?
GreenMoose wrote:
Suppose I have gridnode1, which is used by runner console1 and console2 that may run simultaneously. Will ExclusivelyUsesAttribute ensure that console2 waits for console1 to stop using the resource, if they are both using gridnode1?


Yes :)

The list of used resources is included in the data packet sent by the grid node to the client when it requests additional work, and it is an important consideration for the client when selecting a task to assign to the node.

Post a reply

Log in to reply.