Esempio n. 1
0
        public void ThreadSleepAsyncTestAsync(double sleepSeconds, int threads)
        {
            //-- Arrange
            var sleeper = new Sleeper();

            var expectedPreWaitMilliseconds  = 0;
            var expectedPostWaitMilliseconds = sleepSeconds * 1000;
            var expectedRequest = threads;
            var expectedRun     = threads;
            var expectedTotal   = sleepSeconds * threads;

            //-- Act
            sleeper.RunTimer.Start();
            var actualAsync = sleeper.ThreadSleepAsync(sleepSeconds, threads);
            var actualPreWaitMilliseconds = sleeper.RunTimer.Elapsed.TotalMilliseconds;
            var actualTotal = actualAsync.GetAwaiter().GetResult();
            var actualPostWaitMilliseconds = sleeper.RunTimer.Elapsed.TotalMilliseconds;

            sleeper.RunTimer.Stop();
            var actualRun     = sleeper.ThreadsRun;
            var actualRequest = sleeper.ThreadsRequested;

            //-- Assert
            System.Console.WriteLine(sleeper.ToString());
            Assert.AreEqual(expectedPreWaitMilliseconds, actualPreWaitMilliseconds, 100);
            Assert.AreEqual(expectedPostWaitMilliseconds, actualPostWaitMilliseconds, 100);
            Assert.AreEqual(expectedTotal, actualTotal);
            //-- Maybe I don't care if it knows it's internal state?
            //-- Randomly say you can under half plus one threads into the request by the time we check, due to how fast this works
            // double delta = 1 + threads / 2d;
            // Assert.AreEqual(expectedRun, actualRun, delta);
            // Assert.AreEqual(expectedRequest, actualRequest, delta);
        }