<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: How Can This Test Fail?</title> <atom:link href="http://davybrion.com/blog/2009/06/how-can-this-test-fail/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Sun, 20 May 2012 21:55:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Michael Brown</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-19291</link> <dc:creator>Michael Brown</dc:creator> <pubDate>Fri, 12 Jun 2009 16:02:18 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-19291</guid> <description>I have a theory. You&#039;re not locking your reads and writes to the cache. And your puts are destructive without providing notice that a previous value is being overwritten. If your unit test runner runs the tests concurrently, you have a race in two places. If two calls to your put and get are interleaved the wrong way (a.Put b.Put a.Get) you&#039;ll see that error.Another thing is that your Cache isn&#039;t checking for semantically equal objects.</description> <content:encoded><![CDATA[<p>I have a theory. You&#8217;re not locking your reads and writes to the cache. And your puts are destructive without providing notice that a previous value is being overwritten. If your unit test runner runs the tests concurrently, you have a race in two places. If two calls to your put and get are interleaved the wrong way (a.Put b.Put a.Get) you&#8217;ll see that error.</p><p>Another thing is that your Cache isn&#8217;t checking for semantically equal objects.</p> ]]></content:encoded> </item> <item><title>By: ReSc</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18656</link> <dc:creator>ReSc</dc:creator> <pubDate>Fri, 05 Jun 2009 20:16:57 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18656</guid> <description>This eventhandler has a bug, I think.
&lt;code&gt;
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
_timer.Stop();
Provider.Remove(this.Key);
}
&lt;/code&gt;
and it will &quot;fail&quot; in the following scenario:put object A in cache with key &quot;x&quot; and timeout 10 seconds
wait 9 seconds,
add object B with key &quot;x&quot; and timout 10 seconds.
wait one second,
B gets removed from the cache by the timer event handler of the replaced object A because the timer didn&#039;t get cancelled when A was evicted from the cache.But I would expect B to be removed after 10 seconds have passed after insertion of B.This also means that if any other test in a testrun also uses the key &quot;test&quot; while using the singleton cache , but with a much shorter timeout that falls within your testrun duration, you will see some very intermittant failures.A fix would be to let the timeout handler check if the key is still associated with the same value for which the timeout was set, and to do nothing when the value was updated, or to cancel the timer when a CacheableObject is replaced or removed from the cache.</description> <content:encoded><![CDATA[<p>This eventhandler has a bug, I think.<br
/> <code><br
/> private void Timer_Elapsed(object sender, ElapsedEventArgs e)<br
/> {<br
/> _timer.Stop();<br
/> Provider.Remove(this.Key);<br
/> }<br
/> </code><br
/> and it will &#8220;fail&#8221; in the following scenario:</p><p>put object A in cache with key &#8220;x&#8221; and timeout 10 seconds<br
/> wait 9 seconds,<br
/> add object B with key &#8220;x&#8221; and timout 10 seconds.<br
/> wait one second,<br
/> B gets removed from the cache by the timer event handler of the replaced object A because the timer didn&#8217;t get cancelled when A was evicted from the cache.</p><p>But I would expect B to be removed after 10 seconds have passed after insertion of B.</p><p>This also means that if any other test in a testrun also uses the key &#8220;test&#8221; while using the singleton cache , but with a much shorter timeout that falls within your testrun duration, you will see some very intermittant failures.</p><p>A fix would be to let the timeout handler check if the key is still associated with the same value for which the timeout was set, and to do nothing when the value was updated, or to cancel the timer when a CacheableObject is replaced or removed from the cache.</p> ]]></content:encoded> </item> <item><title>By: Jack</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18620</link> <dc:creator>Jack</dc:creator> <pubDate>Fri, 05 Jun 2009 08:16:00 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18620</guid> <description>An interesting topic, very funny.
Maybe we can investigate the IL</description> <content:encoded><![CDATA[<p>An interesting topic, very funny.<br
/> Maybe we can investigate the IL</p> ]]></content:encoded> </item> <item><title>By: Joshua Cauble</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18603</link> <dc:creator>Joshua Cauble</dc:creator> <pubDate>Fri, 05 Jun 2009 02:22:06 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18603</guid> <description>One question I have is this.  If you run the test locally and step through the code does it pass?  If it passes locally but not on the build server there is a good chance you indeed are running into a race condition.  If you wanted to see for yourself you could always add some logging to spit out the contents of the keys collection to the console so when your unit test runs you can see what is in there.However, since you have a timer in your objects it would be best to add proper locking anyway.Another very easy way to maybe check this is to add simple log statements in the CacheProvider that spits out the key name it&#039;s looking for, the key name you added, etc.  Then in the Elapsed_time event add a log statement that tells you that it&#039;s removing said key.  Match up your console output to what you expect, see if there is any differences.One problem you could run into in a production system is that if the timer goes to Add said value the key might exist and cause a duplicate key exception or some such because your contains runs in a seperate call so by the time the contains returns true or false it could be invalid.ie in your Put on CacheProvider it should look like this:public void Put(CacheableObject value)
{
lock (monitor)
{
if (ContainsKey(value.Key))
{
Remove(value.Key);
}value.Provider = this;
_cacheDictionary.Add(value.Key, value);
value.StartTicking();
}
}This will allow you to create a single Atomic transaction.  Also, on your remove you might want to add something similar that checks the contains key.  As well on your Get command.  You could have a problem that the Contains works fine and the get doesn&#039;t.To verify just add some logging like so to find out:public CacheableObject Get(object key)
{
Console.WriteLine(&quot;Getting data for key: &quot; + key.ToString());
if (_cacheDictionary.ContainsKey(key))
{
Console.WriteLine(&quot;Found Key: &quot; + key.ToString());
return _cacheDictionary[key];
}
return null;
}Hope that might help some.</description> <content:encoded><![CDATA[<p>One question I have is this.  If you run the test locally and step through the code does it pass?  If it passes locally but not on the build server there is a good chance you indeed are running into a race condition.  If you wanted to see for yourself you could always add some logging to spit out the contents of the keys collection to the console so when your unit test runs you can see what is in there.</p><p>However, since you have a timer in your objects it would be best to add proper locking anyway.</p><p>Another very easy way to maybe check this is to add simple log statements in the CacheProvider that spits out the key name it&#8217;s looking for, the key name you added, etc.  Then in the Elapsed_time event add a log statement that tells you that it&#8217;s removing said key.  Match up your console output to what you expect, see if there is any differences.</p><p>One problem you could run into in a production system is that if the timer goes to Add said value the key might exist and cause a duplicate key exception or some such because your contains runs in a seperate call so by the time the contains returns true or false it could be invalid.</p><p>ie in your Put on CacheProvider it should look like this:</p><p>public void Put(CacheableObject value)<br
/> {<br
/> lock (monitor)<br
/> {<br
/> if (ContainsKey(value.Key))<br
/> {<br
/> Remove(value.Key);<br
/> }</p><p> value.Provider = this;<br
/> _cacheDictionary.Add(value.Key, value);<br
/> value.StartTicking();<br
/> }<br
/> }</p><p>This will allow you to create a single Atomic transaction.  Also, on your remove you might want to add something similar that checks the contains key.  As well on your Get command.  You could have a problem that the Contains works fine and the get doesn&#8217;t.</p><p>To verify just add some logging like so to find out:</p><p>public CacheableObject Get(object key)<br
/> {<br
/> Console.WriteLine(&#8220;Getting data for key: &#8221; + key.ToString());<br
/> if (_cacheDictionary.ContainsKey(key))<br
/> {<br
/> Console.WriteLine(&#8220;Found Key: &#8221; + key.ToString());<br
/> return _cacheDictionary[key];<br
/> }<br
/> return null;<br
/> }</p><p>Hope that might help some.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18558</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 15:03:31 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18558</guid> <description>yeah :pbut there is indeed one test that stores 2 objects immediately after each other with the same key...</description> <content:encoded><![CDATA[<p>yeah :p</p><p>but there is indeed one test that stores 2 objects immediately after each other with the same key&#8230;</p> ]]></content:encoded> </item> <item><title>By: Tapio Kulmala</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18556</link> <dc:creator>Tapio Kulmala</dc:creator> <pubDate>Thu, 04 Jun 2009 15:00:23 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18556</guid> <description>... and the theory is wrong because those event will fire 60 secs after the tests...Tapio</description> <content:encoded><![CDATA[<p>&#8230; and the theory is wrong because those event will fire 60 secs after the tests&#8230;</p><p>Tapio</p> ]]></content:encoded> </item> <item><title>By: Tapio Kulmala</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18555</link> <dc:creator>Tapio Kulmala</dc:creator> <pubDate>Thu, 04 Jun 2009 14:57:56 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18555</guid> <description>I&#039; running out of ideas :(Here&#039;s one (hopefully) last theory.Because the remove does not stop the timer, the timer.Elapsed event will always fire once for each cached object. You probably have tests that cache more than 1 object or tests that verify that the put replaces an existing object in the cache. This will result in the situation where multiple timer.elapsed events will fire very close to each other. Each event is handled by a separate thread. Because the CacheProvider and the Dictionary classes are not thread-safe those events might corrupt the internal state of cache/dictionary.Tapio</description> <content:encoded><![CDATA[<p>I&#8217; running out of ideas <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /></p><p>Here&#8217;s one (hopefully) last theory.</p><p>Because the remove does not stop the timer, the timer.Elapsed event will always fire once for each cached object. You probably have tests that cache more than 1 object or tests that verify that the put replaces an existing object in the cache. This will result in the situation where multiple timer.elapsed events will fire very close to each other. Each event is handled by a separate thread. Because the CacheProvider and the Dictionary classes are not thread-safe those events might corrupt the internal state of cache/dictionary.</p><p>Tapio</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18551</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 14:14:54 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18551</guid> <description>nope :)</description> <content:encoded><![CDATA[<p>nope <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Tapio Kulmala</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18550</link> <dc:creator>Tapio Kulmala</dc:creator> <pubDate>Thu, 04 Jun 2009 14:13:40 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18550</guid> <description>Is there anything else running in your TeamCity that could use same CacheProvider singleton and coincidentally use the same &quot;test&quot; key? :-)Tapio</description> <content:encoded><![CDATA[<p>Is there anything else running in your TeamCity that could use same CacheProvider singleton and coincidentally use the same &#8220;test&#8221; key? <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /></p><p>Tapio</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18549</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 14:04:08 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18549</guid> <description>it&#039;s Team City&#039;s nunit testrunner... but as i already said, the time between these tests is never 60 seconds</description> <content:encoded><![CDATA[<p>it&#8217;s Team City&#8217;s nunit testrunner&#8230; but as i already said, the time between these tests is never 60 seconds</p> ]]></content:encoded> </item> <item><title>By: Tapio Kulmala</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18548</link> <dc:creator>Tapio Kulmala</dc:creator> <pubDate>Thu, 04 Jun 2009 14:02:25 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18548</guid> <description>Hi again.What testrunner do you use?If you run the tests directly from visual studio, there will be a different singleton instance for each run. But if you use for example nunit.exe as your testrunner every testrun will share the same instance of your singleton instance. Therefore the timer_elapsed events from an earlier testrun will interfere with your current testrun if the time between your testruns is about 60 secs.
Tapio</description> <content:encoded><![CDATA[<p>Hi again.</p><p>What testrunner do you use?</p><p>If you run the tests directly from visual studio, there will be a different singleton instance for each run. But if you use for example nunit.exe as your testrunner every testrun will share the same instance of your singleton instance. Therefore the timer_elapsed events from an earlier testrun will interfere with your current testrun if the time between your testruns is about 60 secs.</p><p>Tapio</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18519</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 10:35:31 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18519</guid> <description>@Andyyour summary is correct, but the timer doesn&#039;t expire for 60 seconds, and this particular TestFixture never takes that long to run. The CacheProvider is also not used anywhere else.I think it would&#039;ve been better if the CacheProvider was less permissive when it comes to adding items with keys that already exist. But i&#039;m not convinced that the actual cache implementation (or that of the CacheableObject) has a bug...</description> <content:encoded><![CDATA[<p>@Andy</p><p>your summary is correct, but the timer doesn&#8217;t expire for 60 seconds, and this particular TestFixture never takes that long to run. The CacheProvider is also not used anywhere else.</p><p>I think it would&#8217;ve been better if the CacheProvider was less permissive when it comes to adding items with keys that already exist. But i&#8217;m not convinced that the actual cache implementation (or that of the CacheableObject) has a bug&#8230;</p> ]]></content:encoded> </item> <item><title>By: Andy Hitchman</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18516</link> <dc:creator>Andy Hitchman</dc:creator> <pubDate>Thu, 04 Jun 2009 10:28:13 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18516</guid> <description>I came back to see if you had posted a definitive explanation.Is the following summary correct?An object &#039;A&#039; instance with the key &quot;test&quot; is inserted in the cache and its timer starts to tick. Another object &#039;B&#039; with the same key &quot;test&quot; replaces &#039;A&#039; in the dictionary. &#039;A&#039; is now dereferenced and a candidate for GC. However, in some test runs the timer for &#039;A&#039; expires and calls Remove on the cache provider for key &quot;test&quot;, for which the value is object &#039;B&#039;.Looks like a bug in the cache to me, not just a test-time issue.</description> <content:encoded><![CDATA[<p>I came back to see if you had posted a definitive explanation.</p><p>Is the following summary correct?</p><p>An object &#8216;A&#8217; instance with the key &#8220;test&#8221; is inserted in the cache and its timer starts to tick. Another object &#8216;B&#8217; with the same key &#8220;test&#8221; replaces &#8216;A&#8217; in the dictionary. &#8216;A&#8217; is now dereferenced and a candidate for GC. However, in some test runs the timer for &#8216;A&#8217; expires and calls Remove on the cache provider for key &#8220;test&#8221;, for which the value is object &#8216;B&#8217;.</p><p>Looks like a bug in the cache to me, not just a test-time issue.</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18483</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 06:38:02 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18483</guid> <description>as mentioned in one of the earlier comments: yes ;)</description> <content:encoded><![CDATA[<p>as mentioned in one of the earlier comments: yes <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p> ]]></content:encoded> </item> <item><title>By: Sent</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18481</link> <dc:creator>Sent</dc:creator> <pubDate>Thu, 04 Jun 2009 06:17:00 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18481</guid> <description>Do the Cacheable object instances created in the tests share the same key?</description> <content:encoded><![CDATA[<p>Do the Cacheable object instances created in the tests share the same key?</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18474</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Thu, 04 Jun 2009 05:47:37 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18474</guid> <description>@Drewthat definitely sounds like the most plausible explanation but when one of these tests fails, it takes about 10ms to do so, while the other tests all complete almost instantly. 6 of the 7 tests use a time to live of 60 seconds, while the other test uses a time to live of 500ms. But that test waits for 1000ms and then verifies that the object removed itself from the cache.If the test with the short time to live would cause the problem, it should fail as well as any other test whose state got corrupted by it. But it&#039;s always only one failing test.@Andyno, this is with NUnit on a buildserver.</description> <content:encoded><![CDATA[<p>@Drew</p><p>that definitely sounds like the most plausible explanation but when one of these tests fails, it takes about 10ms to do so, while the other tests all complete almost instantly. 6 of the 7 tests use a time to live of 60 seconds, while the other test uses a time to live of 500ms. But that test waits for 1000ms and then verifies that the object removed itself from the cache.</p><p>If the test with the short time to live would cause the problem, it should fail as well as any other test whose state got corrupted by it. But it&#8217;s always only one failing test.</p><p>@Andy</p><p>no, this is with NUnit on a buildserver.</p> ]]></content:encoded> </item> <item><title>By: Drew</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18449</link> <dc:creator>Drew</dc:creator> <pubDate>Thu, 04 Jun 2009 01:54:05 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18449</guid> <description>I think a mix of most of the other comments gives a picture of the whole problem. Here&#039;s my lame attempt at RaymondC-style &quot;psychic debugging&quot;.There&#039;s a race condition. Yes, it&#039;s multithreaded code. There&#039;s a Timer. Yes, it&#039;s unlikely that it will happen. If that&#039;s what&#039;s causing the problem you probably wouldn&#039;t see it often. Maybe once in a blue moon something unexpected causes the tests to take longer to run*. If it&#039;s not the cause of the problem, the race in the test is still a bug IMO. But I&#039;m an SDET - people pay me to say things like that.The Elapsed event changes the state of that key in the CacheProvider singleton. Presumably one that other tests are using. It could be that one test&#039;s timer is messing up another test. Possibly, though, it&#039;s something else slowing the main thread while the timer ticks away.Clearing the timer or somesuch is probably one solution. Not using the singleton might be a good idea, too.* True story: There was a race in one of my tests once that I couldn&#039;t reproduce, but another tester could repro some of the time. It turned out that sometimes (I don&#039;t remember why) that tester would mouse-click on the cmd console running the test so the main thread of the test wasn&#039;t running but the worker it spawned was. Hit any key in the console and the test continued, determined that its activity took too long, and the test case failed.</description> <content:encoded><![CDATA[<p>I think a mix of most of the other comments gives a picture of the whole problem. Here&#8217;s my lame attempt at RaymondC-style &#8220;psychic debugging&#8221;.</p><p>There&#8217;s a race condition. Yes, it&#8217;s multithreaded code. There&#8217;s a Timer. Yes, it&#8217;s unlikely that it will happen. If that&#8217;s what&#8217;s causing the problem you probably wouldn&#8217;t see it often. Maybe once in a blue moon something unexpected causes the tests to take longer to run*. If it&#8217;s not the cause of the problem, the race in the test is still a bug IMO. But I&#8217;m an SDET &#8211; people pay me to say things like that.</p><p>The Elapsed event changes the state of that key in the CacheProvider singleton. Presumably one that other tests are using. It could be that one test&#8217;s timer is messing up another test. Possibly, though, it&#8217;s something else slowing the main thread while the timer ticks away.</p><p>Clearing the timer or somesuch is probably one solution. Not using the singleton might be a good idea, too.</p><p>* True story: There was a race in one of my tests once that I couldn&#8217;t reproduce, but another tester could repro some of the time. It turned out that sometimes (I don&#8217;t remember why) that tester would mouse-click on the cmd console running the test so the main thread of the test wasn&#8217;t running but the worker it spawned was. Hit any key in the console and the test continued, determined that its activity took too long, and the test case failed.</p> ]]></content:encoded> </item> <item><title>By: Andy Hitchman</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18434</link> <dc:creator>Andy Hitchman</dc:creator> <pubDate>Wed, 03 Jun 2009 23:18:10 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18434</guid> <description>Are you running these tests inside VS and do you find that the test fails on a second pass or only when run with other tests that use the CacheProvider. Is the dictionary key you are using unique to this test or is it used elsewhere?1) I have a feeling that test runners in VS re-use app domains/processes which may lead to your singleton-based cache being &#039;dirty&#039;. Perhaps a Flush() method that empties the dictionary and stops all the timers of cached objects?
2) Try replacing &quot;test&quot; with new object() to avoid object.GetHashCode() collisions.</description> <content:encoded><![CDATA[<p>Are you running these tests inside VS and do you find that the test fails on a second pass or only when run with other tests that use the CacheProvider. Is the dictionary key you are using unique to this test or is it used elsewhere?</p><p>1) I have a feeling that test runners in VS re-use app domains/processes which may lead to your singleton-based cache being &#8216;dirty&#8217;. Perhaps a Flush() method that empties the dictionary and stops all the timers of cached objects?<br
/> 2) Try replacing &#8220;test&#8221; with new object() to avoid object.GetHashCode() collisions.</p> ]]></content:encoded> </item> <item><title>By: roberta</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18350</link> <dc:creator>roberta</dc:creator> <pubDate>Wed, 03 Jun 2009 14:24:42 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18350</guid> <description>funny, i recently ran into the same problem, using IDictionary. The ContainsKey method would return false sometimes, even though i had just added the object to it. And whats funnier is that it only happens once in a while, for no apparent reason.</description> <content:encoded><![CDATA[<p>funny, i recently ran into the same problem, using IDictionary. The ContainsKey method would return false sometimes, even though i had just added the object to it. And whats funnier is that it only happens once in a while, for no apparent reason.</p> ]]></content:encoded> </item> <item><title>By: Tapio Kulmala</title><link>http://davybrion.com/blog/2009/06/how-can-this-test-fail/comment-page-1/#comment-18344</link> <dc:creator>Tapio Kulmala</dc:creator> <pubDate>Wed, 03 Jun 2009 13:59:36 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/?p=1412#comment-18344</guid> <description>Hi !In theory....When you remove an object from the cache, you should also clear the provider and the timer of that object. The object is still alive (until the next GC) and the time.elapsed could cause the object to remove an other object from the cache b/c they share the same key.Tapio Kulmala</description> <content:encoded><![CDATA[<p>Hi !</p><p>In theory&#8230;.</p><p>When you remove an object from the cache, you should also clear the provider and the timer of that object. The object is still alive (until the next GC) and the time.elapsed could cause the object to remove an other object from the cache b/c they share the same key.</p><p>Tapio Kulmala</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 3/24 queries in 0.018 seconds using disk: basic
Object Caching 657/657 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-22 12:07:20 -->
