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

Notification

Icon
Error

Concurrency problem
switzer40
#1 Posted : Monday, May 25, 2015 4:37:30 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/25/2015(UTC)
Posts: 2
Location: Germany

The stakeholder wants the application data to be stored as XML in a plain text file that could be read by a tool like notepad - not totally unreasonable. But that causes a problem when testing my CRUD methods. A test must write something to the XML file then read it back in to check that it was written correctly. However, that invariably raises an IOException complainig, that "some other process" is accessing the file. Of course the "other process" is in fact my test process. The section in the NCrunch Docs about concurrency talks about <ExclusivelyUses...> and <Serializable...>, but none of that helps, if the process is interfering with itself.

This must be a pretty common problem, but I haven't been able to come up with a working solution. Anybody got an idea here?
Remco
#2 Posted : Monday, May 25, 2015 9:31:38 PM(UTC)
Rank: NCrunch Developer

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

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

It seems strange that a process would interfere with itself, unless you have written code that would do this in a multithreaded way. Note that NCrunch will never run more than one test inside a test process at the same time, and the ExclusivelyUsesAttribute and SerialAttribute can be used to control concurrency between processes.

I suspect that is something else going on here that we haven't yet considered. How are you handling the file I/O around the text file? Is the file stream being correctly deallocated after the test run?
switzer40
#3 Posted : Tuesday, May 26, 2015 1:28:49 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/25/2015(UTC)
Posts: 2
Location: Germany

I am reading the XML stream with an XMLReader created with XMLReader.Create(Path) and writing to the XML stream with an XMLTextWriter created like so:
Dim Enc As Encoding = New UnicodeEncoding()
Out = New StreamWriter(FullPath)
Writer = New XmlTextWriter(Out.BaseStream, Enc)

I had naively been assuming that it would suffice to close both streams after use, but your question alerted me to the fact that I may also have to do a dispose on each stream after closing it.
However, that does not seem to solve the problem. I´m still getting an IOException when trying to read fom the XMLStream after writing, closing and disposing it. The message of the IOException still says another process is using that file. Weird!
Remco
#4 Posted : Tuesday, May 26, 2015 1:33:54 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Try turning off parallel execution for your solution (http://www.ncrunch.net/documentation/reference_solution-configuration_allow-parallel-test-execution). Does this suppress the problem?
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.038 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download