c# - MSTest unit test passes when in "debug" mode, but fails final assertion in "run" mode -


hi have unit test goes attaches event , updates counter based on property of eventargs in handler so:

protected void updatecounts(object sender, eventargs eventargs) {   lock (lockobject)   {     counts[eventargs.target]++;   } } 

counts static dictionary resource unit tests in class share. assert @ end of test assert count 6 value of target (target enum). when debug through test, passes final assertion, however, when run without breakpoints, count value of target can 7 or 8, never 6.

i realize many threads trying access entry in dictionary may present race condition, why placed lock around increment. have testinitialize method runs before every test gets run looks this:

[testinitialize] public void inittest() {   foreach (targettype x in enum.getvalues(typeof(target)))   {     counts[x] = 0;   } } 

does have insight going on here?

almost every time have run issue boils down race condition less occur when debugging since slowing execution down step through code.

i suggest adding debug or trace statements threads reach various stages of execution in order identify race condition exists.


Comments

Popular posts from this blog

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -