示例#1
0
        public void CreateInstantiatesANewThreadSurrogate()
        {
            // given
            var target = ThreadSurrogate.Create("test");

            // then
            Assert.That(target, Is.Not.Null.And.InstanceOf <ThreadSurrogate>());
        }
示例#2
0
        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.");
        }
示例#3
0
        public void Initialize()
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug($"{GetType().Name} thread started");
            }

            // create sending thread
            beaconSenderThread = ThreadSurrogate.Create(GetType().Name).Start(SenderThread);
        }
示例#4
0
        public void JoinWaitsForTheThreadToFinish()
        {
            // given
            var target = ThreadSurrogate.Create("test").Start(ThreadStart);

            // when
            target.Join(100);

            // then
            Assert.That(ModifiableValue, Is.EqualTo(UpdatedValue));
        }
示例#5
0
        public void JoinOnANotStartedThreadDoesNothing()
        {
            // given
            var target = ThreadSurrogate.Create("test");

            // when
            target.Join(10);

            // then
            Assert.That(ModifiableValue, Is.EqualTo(-1));
        }
示例#6
0
        public void CreateSetsThreadName()
        {
            // given
            const string threadName = "test-thread";

            // when
            var target = ThreadSurrogate.Create(threadName);

            // then
            Assert.That(target.ThreadName, Is.EqualTo(threadName));
        }
示例#7
0
        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);
            }
        }
示例#9
0
        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));
        }
示例#10
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));
        }