title: How to unit test Observable.Sample()?
body: <p>I have a class encapsulating <code>Observable.Sample()</code> such as:</p>
  
  <pre><code>class IntervalRequestScheduler
  {
      private Subject&lt;Action&gt; _requests = new Subject&lt;Action&gt;();
      private IDisposable _observable;
  
      public IntervalRequestScheduler(TimeSpan requestLimit)
      {
          _observable = _requests.Sample(requestLimit)
                                 .Subscribe(action =&gt; action());
      }
  
      public Task&lt;T&gt; ScheduleRequest&lt;T&gt;(Func&lt;Task&lt;T&gt;&gt; request)
      {
          var tcs = new TaskCompletionSource&lt;T&gt;();
          _requests.OnNext(async () =&gt;
          {
              try
              {
                  T result = await request();
                  tcs.SetResult(result);
              }
              catch (Exception ex)
              {
                  tcs.SetException(ex);
              }
          });
          return tcs.Task;
      }
  }
  </code></pre>
  
  <p>How can I test it properly? All my attempts either exit prematurely or cause deadlocks.</p>