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

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -