Build/Test Issues

NCrunch log4Net problem (Log files are getting locked by NCrunch)

Started by reyou on 5,133 views

In my integration tests I am using log4Net. Time to time I am getting

log4net:ERROR [RollingFileAppender] Unable to acquire lock on file publisher.log. The process cannot access the file 'biometrics_publisher.log' because it is being used by another process.

When I check it, NCrunch locks this file and does not release until I make force release.

Is there any resolution for this issue?
Hi, thanks for posting.

NCrunch itself doesn't initiate or hold locks on these files - it has no knowledge of them. The locks are likely being held by your code under test.

There are two likely possibilities here. The first is that the tests are running in parallel and making concurrent use of the log file - see http://www.ncrunch.net/documentation/considerations-and-constraints_concurrent-use-of-test-resources for more information about this problem.

The other possibility is that the tests are not correctly closing the log file when they complete. This probably wouldn't have been an issue when running the tests outside of NCrunch as they would have been run in sequence inside the same process and probably would have used the same file handle. NCrunch, however, will call back into the process multiple times (once for each test batch in the processing queue). See http://www.ncrunch.net/documentation/considerations-and-constraints_test-atomicity for more details on this one.
Maybe a "quickfix" can bet to set "Terminate test runner tasks when all test execution is complete" to true (if statics are keeping log files locked in a task runner process when a new process is spawned trying to aquire lock for it)?
Also you might also have luck in testing using immediate flush ( http://stackoverflow.com/a/15119184 ).

Post a reply

Log in to reply.