Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

System.UnauthorizedAccessException
rlarno
#1 Posted : Monday, October 10, 2011 8:54:41 AM(UTC)
Rank: Member

Groups: Registered
Joined: 9/27/2011(UTC)
Posts: 27
Location: Belgium

Thanks: 6 times
Was thanked: 5 time(s) in 5 post(s)
Hi Remco,

I'm having this intermittent problem that NCrunch runs into this exception:


[10:04:30.6176-BuildTask-48] ERROR (Internal): System.UnauthorizedAccessException: Access to the path 'C:\Users\Rudi.Larno\AppData\Local\NCrunch\7624\23\XXX.Resources\Resources\Pages\ConfigurationUserEdit.resx' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at nCrunch.Core.ProjectItems.SnapshotComponentMember.WriteToFile(String filePath)
at nCrunch.Core.WorkspaceManagement.WorkspaceBuilder.UpdateExistingWorkspaceForComponent(SnapshotComponent component, Workspace& workspace)
at nCrunch.Core.WorkspaceManagement.WorkspaceManager.GetWorkspaceForComponent(SnapshotComponent snapshotComponent)
at nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents)
at nCrunch.Core.BuildTask.DoProcessTaskAndReturnSuccessFlag()
at nCrunch.Core.Processing.ProcessingTask.ProcessTaskAndReturnSuccessFlag()
at nCrunch.Core.Processing.ProcessingQueue.#=qA7cSzOsulmAix2cJIoPNXg==(ProcessingTask #=qks$k1JL1ddaYchGsbF7R0A==)


If I close the solution, and open it again, NCrunch will run perfectly on the solution.
Remco
#2 Posted : Monday, October 10, 2011 11:29:55 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Thanks for reporting this one - I've had a couple of bug reports come through with a similar thing (I think one of them was yours). My best guess at the moment is that TFS is setting read-only locks on the files in your solution, and these read-only flags are being copied into the workspace by NCrunch (where they cause lock issues later down the line).

Hitting the reset button when you see this should wipe out the workspaces and allow you to continue on as normal. I'll see what I can do about getting a fix implemented for this.
Remco
#3 Posted : Tuesday, October 18, 2011 6:28:21 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
This issue should be fixed in the 1.35b build that was released this morning.
Slampen
#4 Posted : Monday, January 7, 2013 12:04:02 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/20/2012(UTC)
Posts: 4
Location: Norway

Thanks: 1 times
Remco;522 wrote:
This issue should be fixed in the 1.35b build that was released this morning.


I guess not.

[13:00:22.7104-BuildTask-232] ERROR (Internal): System.UnauthorizedAccessException: Access to the path 'C:\Users\stian.TRUSTEE\AppData\Local\NCrunch\14116\144\Trustee.Test\bin\Debug\app.config' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at nCrunch.Core.BuildManagement.BuildEnvironment.#=q8$LOKWk7D7lyGZIwP13jNjJ$brCHpL1e7G$0pcYV$p94soCUF7aNxtkfQpG$Ek4n(String #=qAp3WT2Jf6NIq1L0m7RFjxlNwlB1h5WNYRRGgRKRlz64=, IList`1 #=qQ2LRHf76Zqny9HxLTzTkmH5wZyPEVIP7nrlcwTA5oT8=)
at nCrunch.Core.BuildManagement.BuildEnvironment.Build(SnapshotComponent snapshotComponentToBuild, IList`1 referencedComponents)
at nCrunch.Core.BuildTask.DoProcessTaskAndReturnSuccessFlag()
at nCrunch.Core.Processing.ProcessingTask.ProcessTaskAndReturnSuccessFlag()
at nCrunch.Core.Processing.ProcessingQueue.#=qDrBzqyGPPU_pa0BAdREZfQ==(ProcessingTask #=qGnrUt34OOiQg6sfGxTG7jA==)



Runing 1.43.
Remco
#5 Posted : Monday, January 7, 2013 9:31:12 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for sharing this issue.

Although the symptom is the same, my suspicion is that the issue you're experiencing is being caused by the above file being locked by a process - rather than a read-only flag.

Assuming it happens consistently, are you able to check whether terminating any running processes will allow you to modify the file? Look specifically at processes that may be launched by your tests.
Rodney
#6 Posted : Thursday, March 21, 2013 4:06:49 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
I have been having this problem lately with 1.44.

It has to do with your tests running over and over and NCrunch is the one locking the file that is getting the exception. Like rlarno stated if you close the solution and reopen it it works for a while. Eventually though it will come back and you will have to close VS or close the solution.

I have noticed that there are a number of NCrunch processes still running more than the number of Visual Studios opened (I never have the same solution or projects open by more than one VS). Overtime if I I have noticed about 10, but only had 2 visual studios open at the time. When I clicked all of them only two came back. I would suspect that there should only ever be two. Even so those two should also make sure they have unloaded all the tests and DLL's associated with it may be best to let the process close and start a new one to be safe.

It is really hard to trust the test runner when you have issues like this that only occur in the test runner but not in the real world.
Remco
#7 Posted : Thursday, March 21, 2013 4:33:46 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Rodney,

NCrunch will spawn as many test and build runners as necessary to meet its parallel execution needs. This is controlled by the Max number of processing threads configuration setting, and NCrunch will also pool processes to avoid the performance penalty of needing to spin them up in future. This is by design and means that you will always have a number of NCrunch processes running in the background at any one time.

Note that NCrunch processes routinely execute user code. This means that if you have a test holding a file lock beyond the scope of its execution, then this will show up as the lock being held by an NCrunch task runner. Ensure that files used by your tests are properly closed and cleaned up when tests finish execution.

As you've mentioned you have an abundance of test runner processes running in the background, I suspect that there is a strong possibility you are running tests in parallel that have not been designed with this in mind. If you haven't already, it's worth having a read of the documentation around parallel execution as this can have implications for the design of tests, especially those that make use of the file system.

Cheers,

Remco
Rodney
#8 Posted : Thursday, March 21, 2013 4:47:33 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Fine that explains why there are so many of them. However there is no excuse for them to be holding locks on files that my tests copied and then want to copy again to over write on another run in the temp folder.

This is not a parallel issue as the unit tests themselves work usually and when they stop I do what I stated above and they start working again. The biggest issue is I am trying to run an application to use it a the dev to test it and verify things unit tests can't. It uses a library that has unit tests. Your process hold locks on the files used by those libraries during the unit tests. Those same files are also used by the application of course and it needs to be able to run, however it crashes because ncrunch is holding locks.

I have set all tests to run manually so they are not doing anything without my action. And those processes once they run a unit test they hold locks one the files. Why can't the process just end after a run, and then start a new one when its time to do a new run?

So the work around is to set all my solutions to run tests manually, and then kill all your process anytime they are holding locks. Doing this removes all the reasons why we purchased your product. It is no longer automatic and it is NOT saving us any time, it is not costing us time as it is creating its own bugs that we have to trouble shoot to make sure they are not our bugs but yours. Every moment we spend trouble shooting NCrunch issues is time we are not spending on our own projects.

If this was a free product still I wouldn't be upset I would just move on. However it is not free and we are paying for something that is supposed to save time and it has not. It has been costing us days and soon weeks of lost time on our current project.
Remco
#9 Posted : Thursday, March 21, 2013 10:30:28 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Rodney,

As you've described that the files being locked are resources being used by your application, this means that the locks are being opened and held by your code. NCrunch does not control or manipulate the execution of your code, so if your tests hold the locks after they finish execution, the locks will persist and they will interfere with subsequent test execution. If your tests (or code under test) are opening up file locks on resources and you have the Allow parallel test execution setting set to TRUE, then you will experience situations where two concurrently executing tests try to access the same file at the same time, which will usually result in a locking IOException.

The reason your tests are demonstrating this problem with NCrunch is because they were originally designed to work with a manual test runner that executes all tests in sequence, then tears down the process at the end of the test run. NCrunch will re-use processes for multiple test runs and can execute tests in any order, so if the tests don't clean up properly, you can experience state related issues such as this. My concern is that from what you've described, it's also possible that your production code is keeping these file locks open during normal application execution, which may be undesirable.

Broadly, you can solve this in two ways, either by scaling back some NCrunch features through configuration, or by re-engineering the tests and making use of ExclusivelyUsesAttribute.

Please try the following configuration options:
Set Allow parallel test execution to FALSE
Set Max test runners to pool to 0
Set Terminate test runner tasks when all test execution is complete to TRUE

I really recommend taking half an hour out to thoroughly read through the NCrunch documentation, especially the details around test atomicity, parallel execution, and the test troubleshooting page. If the product is costing you as much time as you say it is, this half hour will pay for itself very quickly. Please try to understand that without access to your source code, this is the only way I can help you to make best use of the product. NCrunch does not function the same way as other non-continuous test runners, the continuous aspect introduces new constraints for your tests that are worth becoming familiar with.


Cheers,

Remco
Rodney
#10 Posted : Thursday, March 21, 2013 11:42:57 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)

1. I have troubleshooted this to your process holding the locks because it never really exits and the tests are testing an API that holds on to resources by design until the application that called it finishes. This is because the cost of using these resources is high initially, but to keep them around while the app is running is keeps it fast, and then it will clean up when the app exits. Since the app is YOURS and you never exit it never cleans up, and on the next run there is a chance they will be held by a different process.

2. I have been using NCrunch for almost 18 months now and all my tests are written with it in mind and that they will be running in the background and in parallel. However when it just can't be avoided I will disable parallel test execution for that solution. I have verified that it appears that running with parallelism turned off keeps the tests running better within the NCrunch world. However this is a SOLUTION wide setting and brings with it its own problems.

2a. All tests in a solution because of this are now forced to run asynchronously.
2b. If the NCrunch processes would just expect and start again only when needed and not share anything from one run to another this would not be needed. My tests run in parallel fine, as I have implemented a feature in the API that will not delete the file, however when you switch from 32 bit to 64 bit the file has to change and it is being locked and it is only being locked in parallel mode for some reason and not in asynchronous mode. So if the process would exit like the real world apps the code being tested is expected to run in then all the problems go away.
2c. It would be nice if this could be set at a project level and not just at a solution level, as most projects are fine, and when this occurs it usually just a few tests which we could then isolated into their own test project and then flag to not be parallel if provided also at the project level.

3. While Terminate test runner tasks when all test execution is complete sounds like it is what is needed it is not, I have set it to TRUE and it doesn't address the issue. However I like what it is doing, and it is working more as I would have expect it to work in the first place. Not sure why this is not TRUE by default.

4. I don't see how ExclusivelyUsesAttribute applies here, READING the files in question is SHARED just fine, it is when I need to DELETE the file that it gets un-happen that another process is still holding a lock on the file. I only have to delete technically if the bit-ness changes between runs.

5. I have read your documentation as needed. However the product should just WORK, it should have an good user experience and work as the typical user would expect. It should help the user to learn and be as inductive as possible. Just because you are developing tools for developers doesn't mean you can take short cuts and ignore user experience. Also your documentation would take WAY MORE than 30 minutes to read it all, and then you would forget most of it if you don't use it right away. That is why Documentation for tools and software API's are REFERENCE based documentation that you only look at a quick start type 5 minute thing to make sure you understand the basics and then look up information as you needed. If you tool can't be properly used without taking hours and hours to fully reading and understand all your documentation then there is a problem with your user interface and workflows.

I am not sure why you are resistant to at least proving a setting at the All Solutions level that would force all the processes to exit between runs, is there some low level cost that is just to expensive or not worth it that makes this impractical?

I am going to go back to the drawing board and see if there is something else that can be done in my design of the API, but short of forcing the user of the API to say "I'm Done" and then the next time they go do doing something would start the expensive initialization process again.

However I shouldn't have to redesign an API around the testing tools, when they are designed to work in a real world situation that the testing tool doesn't support.
Remco
#11 Posted : Friday, March 22, 2013 2:39:21 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Rodney;3865 wrote:

1. I have troubleshooted this to your process holding the locks because it never really exits and the tests are testing an API that holds on to resources by design until the application that called it finishes. This is because the cost of using these resources is high initially, but to keep them around while the app is running is keeps it fast, and then it will clean up when the app exits. Since the app is YOURS and you never exit it never cleans up, and on the next run there is a chance they will be held by a different process.


Can you share any details about the resources being locked by your code under test, and how these resources are obtained? Perhaps I can suggest approaches that will allow the resources to be kept separate between the test processes so that they don't interfere with each other.

Rodney;3865 wrote:

2. I have been using NCrunch for almost 18 months now and all my tests are written with it in mind and that they will be running in the background and in parallel. However when it just can't be avoided I will disable parallel test execution for that solution. I have verified that it appears that running with parallelism turned off keeps the tests running better within the NCrunch world. However this is a SOLUTION wide setting and brings with it its own problems.


There is a more granular approach to controlling the concurrency between tests, using ExclusivelyUsesAttribute. This attribute allows you to specify which of your tests can be executed concurrently, and which can not. It's also worth having a look at SerialAttribute, which is a somewhat clumsier but simpler alternative to ExclusivelyUsesAttribute.

Rodney;3865 wrote:

2a. All tests in a solution because of this are now forced to run asynchronously.
2b. If the NCrunch processes would just expect and start again only when needed and not share anything from one run to another this would not be needed. My tests run in parallel fine, as I have implemented a feature in the API that will not delete the file, however when you switch from 32 bit to 64 bit the file has to change and it is being locked and it is only being locked in parallel mode for some reason and not in asynchronous mode. So if the process would exit like the real world apps the code being tested is expected to run in then all the problems go away.
2c. It would be nice if this could be set at a project level and not just at a solution level, as most projects are fine, and when this occurs it usually just a few tests which we could then isolated into their own test project and then flag to not be parallel if provided also at the project level.


I think there may be a way that this can be done with your present setup. Although NCrunch attributes don't yet work at project level (this is much requested and will be happening soon), you may be able to make use of the IsolatedAttribute on the tests that need to have their process torn down on completion. Tests marked with this attribute will always be run within their own distinctive process that exists only for the lifetime of the test execution. When combined with the concurrency restrictions (either through ExclusivelyUsesAttribute or the solution-level configuration setting), I think this may solve the problems you've described.

Rodney;3865 wrote:

4. I don't see how ExclusivelyUsesAttribute applies here, READING the files in question is SHARED just fine, it is when I need to DELETE the file that it gets un-happen that another process is still holding a lock on the file. I only have to delete technically if the bit-ness changes between runs.


I guess this depends upon the timing of the operations. If the shared file can deleted anywhere within the scope of a test, then in theory this test cannot be run concurrently with any other test that may read the file. The concurrency control handled by NCrunch is granular only to test level (i.e. you can't restrict concurrency based on certain parts of the test being executed). It may be technically possible to use some kind of O/S wide mutex to control access to the file, but this would be messy and I probably wouldn't recommend it. ExclusivelyUsesAttribute is still your best bet for making sure two (or more) incompatible tests don't run at the same time. The approach that you've taken with engineering your code so that the file is not deleted during a test run is sensible and will give you far more parallelisation capability.

Rodney;3865 wrote:

I am not sure why you are resistant to at least proving a setting at the All Solutions level that would force all the processes to exit between runs, is there some low level cost that is just to expensive or not worth it that makes this impractical?


Basically, because it's expensive to build the test environment. In the processing queue, you'll notice that NCrunch breaks up the tests into separated tasks to be processed in chunks. These chunks each involve a fresh call into the test runner, making them each effectively a small test run. If the process were to exit between each test run, each of these tasks would need to build a whole fresh test environment from scratch. The cost of building the test environment is considerable - it requires JITing all assemblies in the environment, and reinitialising the test framework, along with any other system-related operations involved in building the process. If you were to attribute each of your tests with the IsolatedAttribute, you'll see exactly this behaviour, and full test cycle time increases of 500% or more are not unheard of.

It would be fair to question why the behaviour of the NCrunch engine is to break the tests up into chunks and run them as separated test runs. The reasoning behind this comes back mostly to performance and complexity. For example, it can be very difficult to steer a 3rd party test framework through a dynamic test run that is being built on the fly (as the execution order of tests is non-deterministic during parallel execution). The behaviour is so deeply embedded within the NCrunch engine that there's simply no way to change it this late in the project.


Cheers,

Remco
Rodney
#12 Posted : Friday, March 22, 2013 4:46:47 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
1. We have two DLL that are copied out and then referenced on is a native library and the other is a mixed-mode on. The native one is not as much of an issue as it has less of an issue with some changes I made since it is not a C# DLL loaded into the AppDomain. The Mixed-Mode one however is the biggest issue is because it is an embedded resource that we copy out the correct "bit" version to the users temp folder and then we load it into the current AppDomain. Once it is loaded .Net is locking the file and it will remain locked until the AppDomain is unloaded. The only way to unload the default AppDomain is to exit the application. There are no ways around that. We also require the application to be in the default AppDomain and don't want to add complexity of multiple AppDomains just so we can unload one. In the REAL WORLD there are no issues with this. The user doesn't change the BIT version of their operating system on the fly and we don't need to touch the file while the app is running. However we do want to make sure we replace the file on the next launch just in case they upgraded the app and a new version was embedded. Regardless NCrunch doesn't allow for testing this library as it will never exit its process which will therefore never unload the default AppDomain. The Native once since it is not locked by it gives us some control if we wanted to use it, however we only needed to implement these extra controls for NCrunch as they are not required in a real world use situation.

2. First as I said before ExclusivelyUsesAttribute is not applicable to this situation, there is not "Resource" that this can be tied to that it would help prevent .NET AppDomain from locking the resource in question. As for SerialAttribute that has promise but we cannot have a dependency on NCrunch only NUnit. So as long as we can bring all the attributes into our world, either into the test project itself, or into the common library we use then great. Even better if it doesn't require the NCrunch namespace and can be wrapped in ours it will be easier to use. ReSharper allows both of these with their attributes. I will try this out and see how far I can get with this. I still think it would be nice to ALSO have the parallel feature at the project level too. As to why you think SerialAttribute is clumsier that ExclusivelyUsesAttribute is odd, there are very different and serve completely different purpose. I think it is clumsier than being able to just set a at the project level the parallelism settings available at the solution level.

FYI - You may want to proof read your documentation link you provided for SerialAttribute as it has the wrong attribute source. It is showing source for IsolatedAttribute instead of SerialAttribute.


2a,b,c. Now you are bring up the IsolatedAttribute that is mistakenly listed under the SerialAttribute. I was wondering if it was real or something that was renamed and the docs where never updated. This one holds promise possibly, and I will have to play with it as well.

4. Well that is the problem IT CAN'T BE DELETED because of the issues explained above in #1. Your IsolatedAttribute may work, I have to try it and find out. As in the real world I am not trying to start the equivalent of 20 applications at the same time that needs to load a DLL into the current AppDomain, and are each trying to override the file when they start.

Overall I like that NCrunch runs tests in parallel and breaks them up into separates tasks to be processed in chunks. This not only allows for faster runs, but it also typical can find additional bugs that a serial test run wouldn't find. However in some situation it doesn't find the bug but is causing issues. In this case you may have attributes that will help.

In 18 months I never even new you had these, and I always though it would be great if you did. It would be nice if you made these more visible, possibly give them a call out at the end of the Quick Start Guide that is the only document you can realistically expect someone to read. You have a nice wizard that walks people through setting up the engine when first enabled. It may be nice to add to this or have something similar that explains some of the quick start items and lets them know there are advanced features such as attributes, and list any others and provided links to these area of the documentation.

If the IsolatedAttribute works as it states then it may be a satisfactory work around to the issue.


Rodney
#13 Posted : Friday, March 22, 2013 5:38:15 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
Update: the attributes do require them to be in the namespace NCrunch.Framework and can't be placed in another. Using Isolated and Serial together appears to allow the test to run as if I set the Allow Parallel settings to false, and those tests do take longer to complete now as expected under this situation.

However this only seems to work in x86 and AutoDetect (which seems to AutoDetect Any to be x86 for some reason, and is not AutoDetecting the system hardware like other test runners). When I change the test project NCrunch config to use x64 it just failes all tests instantly stating the a BadImageFormatException, stating it couldn't compile the test dll it could not load a file or assembly for the test DLL or one of its dependencies. An attempt was made to load a program with an incorrect format. This is usually a 32 bit trying to reference a 64 bit DLL issue. However I checked ALL the projects in the solution not just the ones the Test DLL references and they are all set to ANY. So I closed all Visual Studios and waited for all the NCrunch processes to stop and then launched just this solution in question. When it came back up I am prompted with the NCrunch License Details stating that I am using 30 day eval and my license fields where empty and grayed out. This is very odd, its like NCrunch just reset itself back to default settings and wiped out my license details.

So I enter the details again but everything is still the same it can't compile my test. I even turned on assembly binding logging, but it doesn't help as it shows the assmbly name is unknown and it only shows the test DLL as the one it attempted to load.

BTW at no time does visual studio have any issues building this project, only NCrunch is having the issue building it.

Anyway, so I decided to disable NCrunch and then Enable it again without closing Visual Studio and for some reason what ever that does fixed NCrunch and allowed it to build again.

So something odd just occurred that maybe unrelated to any of the previous things other than this is the first time I have used any attributes and I am using ones that force isolation and serial processing.
Remco
#14 Posted : Friday, March 22, 2013 11:02:50 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi Rodney -

We're establishing a few parallel lines of communication now, so I'll try to break up the areas of discussion and we'll work through them separately :)


Regarding the locking of the mixed mode resource assembly:

I get the impression that you've managed to find workarounds for the problems you're experiencing with this one (please do correct me if I'm wrong). Something I can suggest that you may find useful is to introduce alternative naming of the resource file according to the process ID of the process that is executing it. For example, if you have the file normally called 'MyEmbeddedResource.dll', and this is being loaded into your application domain dynamically (perhaps by Assembly.LoadFrom), you could copy the file to a name derived from the process ID prior to it being loaded, for example:

var resourceFileName = "MyEmbeddedResource_" + Process.GetCurrentProcess().Id + ".dll";
File.Copy("MyEmbeddedResource.dll", resourceFileName);
Assembly.LoadFrom(resourceFileName);

.. Because the process ID is always specific to the NCrunch (or test) process being used to host the environment, it will always be unique. In this way you can prevent the runners from interfering with each other. This does mean yet more deviation from the normal runtime behaviour of your application, although the benefits would probably outweigh the cost. Not completely sure if this is something you want, but I thought I'd suggest it.



Regarding ExclusivelyUsesAttribute:

Where a physical resource doesn't exist, you can simply substitute its name for the name of an arbitrary mutex. The main function of this attribute is to declare some kind of name that can never be shared by two tests executing at the same time. So you could just use 'ExclusivelyUsesAttribute("LocksFiles")' on all the tests that can experience file locking issues. This would be better than marking each test with SerialAttribute, as the tests with ExclusivelyUsesAttribute would be unable to run concurrently with each other, where the SerialAttribute tests cannot run concurrently with anything (i.e. you may have other tests that can run perfectly normally without ever caring about the file locks).



Regarding SerialAttribute documentation:

Thanks for making me aware of this, I'll see that the documentation is corrected.



Regarding attribute documentation in general:

I'm sorry that these weren't well referenced in the documentation, especially from the quick start page. As you're an early user of NCrunch, you may also have been at a disadvantage here, as both SerialAttribute and IsolatedAttribute were added within the last 12 months. I'll add some extra notes to the quick start page to help make people more aware of them.



Regarding attribute namespacing:

As much as I would like to change this so that NCrunch would detect and work with attributes outside the NCrunch namespace, I think it may cause great problems for a minority of users due to potential naming clashes with other products and tools. While I seriously doubt that anyone would create an attribute called 'ExclusivelyUsesAttribute', more generically named attributes such as SerialAttribute and IsolatedAttribute (already used by TypeMock Isolator) are likely to clash. More foresight could have given better options here, but now that the attributes are named and used as they have been, unfortunately they can never be changed.


Regarding NCrunch forgetting the license key:

Sorry about this. There is a known problem that can cause this to happen. A fix is pending for this issue in the 1.45 release due out within the next week.


Regarding the BadImageFormatException that went away after a reset:

My first thought about this is that it may be caused by a synchronisation bug of some kind between the NCrunch configuration and the underlying projects. In theory, changing the NCrunch project configuration should cause the project to be re-loaded and rebuilt. If there's a config setting that for some reason didn't do this, I can see how this problem might occur. I'll review the applicable options in this case to see if I can reproduce this problem. If you can make it happen again, I'd really like to learn more about it.



Thanks!

Remco
Rodney
#15 Posted : Monday, March 25, 2013 6:16:06 PM(UTC)
Rank: Member

Groups: Registered
Joined: 12/7/2012(UTC)
Posts: 17
Location: United States of America

Thanks: 1 times
Was thanked: 2 time(s) in 2 post(s)
For the most part I have moved on as everything is "working", even if its not a clean as I would like it for the unit tests. The update was just to let you know of an oddity I experienced with NCrunch implementing the changes around your suggestions with the attributes.

The renaming trick works find for the native DLL's and I am already doing that for those, the issue is on Signed embedded Mixed-Mode DLL's it requires the DLL name to be unmodified or it wouldn't work. I tried that first thing with it but couldn't' get it to work unless it was the original name. I assumed it was part of the security with the strong naming and signing.

Your explanation of ExclusivelyUsesAttribute is much more clear than what is in the documentation. The documentation gives the impression that it will actually monitor the physical resource on disk. All you really are doing is creating Mutex concept with string naming. I then use "keywords" to tag the ones that are using similar excusive resources, and i can use more than one keyword so that I can mix and match to allow for a more complex resource usage across tests.

Thanks for your help Remco and sticking through it me. :)
Remco
#16 Posted : Monday, March 25, 2013 8:35:05 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,989

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Great to hear that the big issues are solved. It is unfortunate that environments do still exist where NCrunch needs special attention (i.e. extensive configuration and messing around with tests). Usually these tend to be solutions that involve a lot of extensive integration testing and cross-platform setup, but like anything in the software world, you do always get there. Thanks for taking the time to explain the issues you've experienced in such detail, as this helps with planning further changes to NCrunch to make life easier for everyone.

I've updated the documentation around ExclusivelyUsesAttribute to improve the description. It's quite rare that I get good constructive feedback on the documentation, so if you do find anything else that you feel could be improved, please do let me know. The documentation changes will all be rolled out with the 1.45 release in a few days :)


Cheers,

Remco
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.175 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download