﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ayende Rahien commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Peter,
  
This is used in the tests. 
  
The way that the tests work is by spinning out a new scenario, which can be in a separate app domain or a separate process.
  
Except for the messages, there are no communication between the test code and the scenario. Trying to add one would significantly complicate the code.
  
Since the scenarios are one shot things (they execute only once), we can be sure that once they stopped sending messages,we are good
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment10</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment10</guid><pubDate>Sun, 24 May 2009 09:29:40 GMT</pubDate></item><item><title>Peter Morris commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Fixed my email address, sorry for the inconvenience :-)
  
  
Is there no way of knowing that a message is due to come in?  The problem I see (being awkward) is this
  
  
"What happens if a message comes in after 0.51 seconds?"
  
  
Is there no central dispatcher or something which knows how many messages are dispatched, so you can wait until that many messages have been received?
  
  
Or maybe if your test knows how many messages it sends and waits for that many to turn up before completing?
  
  
Just throwing out ideas, I really can't stand Thread.Sleep in test code :-P
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment9</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment9</guid><pubDate>Sun, 24 May 2009 09:20:15 GMT</pubDate></item><item><title>Ayende Rahien commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Peter,
  
It is a message queue, yes.
  
That wouldn't work, I need to also wait for new messages that come into the queue after everything has processed.
  
The exit condition is:
  
queue is empty, all messages has been processed and no new messages came in for 0.5 second
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment8</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment8</guid><pubDate>Sun, 24 May 2009 09:14:26 GMT</pubDate></item><item><title>Peter Morris commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>This looks like some kind of job queue with threads, am I right?
  
  
Why don't you have a ManualResetEvent on the MailBox which gets set when the queue is empty and the last job has been processed?  Then you'd only need this in your tests
  
  
MailBox.Emptied.WaitFor();
  
  
and the setting / resetting of the event could be done within the MailBox class using lock() in the relevant places.
  
  
I am always suspicious when I see a Thread.Sleep in a test...always :-)
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment7</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment7</guid><pubDate>Sun, 24 May 2009 08:58:14 GMT</pubDate></item><item><title>Fabio Maulo commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>[www.nunit.org/index.php?p=delayedConstraint&amp;r=2.5](http://www.nunit.org/index.php?p=delayedConstraint&amp;r=2.5)</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment6</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment6</guid><pubDate>Sat, 23 May 2009 04:10:17 GMT</pubDate></item><item><title>Ayende Rahien commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>I find the first one more readable
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment5</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment5</guid><pubDate>Sat, 23 May 2009 00:14:56 GMT</pubDate></item><item><title>configurator commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Just a small question, why do you do
  
countOfTimesTriesToWaitAndThereWereNoMessages += 1;
  
And not
  
countOfTimesTriesToWaitAndThereWereNoMessages++;
  
? Isn't the second example a bit more readable?
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment4</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment4</guid><pubDate>Sat, 23 May 2009 00:10:26 GMT</pubDate></item><item><title>Frank Quednau commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Thumbs up for the aptly named "countOfTimesTriesToWaitAndThereWereNoMessages" . I would like to see more of that!
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment3</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment3</guid><pubDate>Fri, 22 May 2009 21:04:18 GMT</pubDate></item><item><title>Ayende Rahien commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Steve,
  
This is actually a code that is here to support the _tests_
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment2</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment2</guid><pubDate>Fri, 22 May 2009 19:04:27 GMT</pubDate></item><item><title>Steve Smith commented on Waiting, it isn’t as simple as twiddling your thumbs</title><description>Oren,
  
  If you want to test this code, it's often helpful to replace the direct calls to Thread.Sleep() with interfaces and DI them.  I've often suffered from nasty looking tests when Thread.Sleep was involved in the SUT unless I've done something like this.
</description><link>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment1</link><guid>http://ayende.com/4030/waiting-it-isn-t-as-simple-as-twiddling-your-thumbs#comment1</guid><pubDate>Fri, 22 May 2009 18:35:50 GMT</pubDate></item></channel></rss>