public void Dispose_EnterBusyThrowsObjectDisposedExceptionIfDisposed() { var t = new TestDisposable(); t.Dispose(); t.DoWorkWithBusyToken(1000); }
public void Dispose_BlockedWhileObjectBusyToken() { int doWorkDelayTimeInMs = 1000; var t = new TestDisposable(); var sw = new System.Diagnostics.Stopwatch(); sw.Start(); using (var signal = new System.Threading.ManualResetEvent(false)) { System.Threading.ThreadPool.QueueUserWorkItem( (reserved) => { signal.Set(); t.DoWorkWithBusyToken(doWorkDelayTimeInMs); } ); signal.WaitOne(); System.Threading.Thread.Sleep(16); t.Dispose(); } sw.Stop(); //If the test takes less time than the amout of time DoWork delayed for, //then dispose didn't stop/wait for the busy flag and this represents a bug. Assert.IsTrue(sw.Elapsed.TotalMilliseconds >= doWorkDelayTimeInMs); }