public void CreateInstantiatesANewThreadSurrogate() { // given var target = ThreadSurrogate.Create("test"); // then Assert.That(target, Is.Not.Null.And.InstanceOf <ThreadSurrogate>()); }
public void AStartedThreadThrowsExceptionIfStartIsCalledAgain() { // given const string threadName = "test"; var target = ThreadSurrogate.Create(threadName).Start(ThreadStart); // when Assert.Throws <InvalidOperationException>(() => target.Start(ThreadStart), $"Thread {threadName} already started."); }
public void Initialize() { if (logger.IsDebugEnabled) { logger.Debug($"{GetType().Name} thread started"); } // create sending thread beaconSenderThread = ThreadSurrogate.Create(GetType().Name).Start(SenderThread); }
public void JoinWaitsForTheThreadToFinish() { // given var target = ThreadSurrogate.Create("test").Start(ThreadStart); // when target.Join(100); // then Assert.That(ModifiableValue, Is.EqualTo(UpdatedValue)); }
public void JoinOnANotStartedThreadDoesNothing() { // given var target = ThreadSurrogate.Create("test"); // when target.Join(10); // then Assert.That(ModifiableValue, Is.EqualTo(-1)); }
public void CreateSetsThreadName() { // given const string threadName = "test-thread"; // when var target = ThreadSurrogate.Create(threadName); // then Assert.That(target.ThreadName, Is.EqualTo(threadName)); }
public void StartExecutesGivenThreadStart() { // given var target = ThreadSurrogate.Create("test"); // when target.Start(ThreadStart); threadFinishedEvent.WaitOne(100); // then Assert.That(ModifiableValue, Is.EqualTo(UpdatedValue)); }
public void Initialize() { if (logger.IsDebugEnabled) { logger.Debug($"{GetType().Name} Initialize() - thread started"); } lock (this) { sessionWatchdogThread = ThreadSurrogate.Create(GetType().Name).Start(WatchdogThreadStart); } }
public void SleepReturnsFalseIfInterrupted() { // given const int sleepTime = 1000; var target = CreateInstance(); var task = new ExecutableTask(target, sleepTime); // when var thread = ThreadSurrogate.Create("test").Start(task.Process); thread.Join(500); // then Assert.That(task.SleepOutCome, Is.EqualTo(0)); }
public void WakeUpInterruptsSleep() { // given const int sleepTime = 5000; var target = CreateInstance(); var task = new ExecutableTask(target, sleepTime); // when var thread = ThreadSurrogate.Create("test-thread").Start(task.Process); target.WakeUp(); thread.Join(sleepTime); // then Assert.That(task.SleptTime, Is.LessThan(sleepTime)); }