title: Unit test - how to check that a class accessed external resources in parallel?
body: <p>I have a class which reads some data from web services.
  It is supposed to do it in parallel.
  I want to write a unit test to ensure it does it in parallel and not sequentially.</p>
  
  <p>I have replaced a web service by a stub which generates a delay (eg 1 second).
  I measure the total execution time. If the method call took less than (delay * 1.1), I assume that processing happened in parallel and the test passes.</p>
  
  <p>Is there a more elegant way to implement this test (eg by measuring number of threads)?</p>
  
  <p>PS The class is currently using TPL to implement parallel calls:</p>
  
  <pre><code>IEnumerable&lt;Task&lt;ItineraryExternalReference&gt;&gt; asyncTasks = from dataSourceSiteId in dataSourceSiteIds
                                                             select this.ProcessBookingAsync(dataSourceSiteId, booking);
  
  var externalReferences = await Task.WhenAll(asyncTasks);
  return externalReferences;
  </code></pre>