c# - NUnit copying ILogicalThreadAffinative items in CallContext to new threads -


i've run issue nunit , callcontext (using c#) nunit copying in existing call context extends ilogicalthreadaffinative when new thread created. example, in following example exception thrown in newly-created thread:

    [test]     public void testcopiedcallcontext()     {         foo f = new foo();         f.a = 1;         callcontext.setdata("test", f);         new thread(new threadstart(delegate()         {             if (callcontext.getdata("test") != null)             {                 throw new exception("bad!");             }         })).start();         thread.sleep(500);     }      class foo : ilogicalthreadaffinative     {         public int a;     } 

if foo doesn't extend ilogicalthreadaffinative test passes. i'm using .net 2.0 (due other restrictions cannot use newer versions of .net). i've tried using requires* attributes available in latest version of nunit no success. know how turn behavior off?

i dont beleive can attempting do. 1 person has suggested putting code assembly test runner has access it.

there blog post know about, describes issue is.

unit testing code multithreading can challenging , tend isolate threads , wrap static objects.

if me, think try isolate callcontext.setdata , callcontext.getdata wrapping call context in class callcontextwrapper : icallcontextwrapper.

the test code uses contextwrapper.setdata("test", f) , done it;

i trust whoever wrote callcontext tested it's ability take in data , transfer new thread. imo callcontext framework code should have been tested need isolate code's dependency on callcontext.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -