public void ShouldResetThroughput() { var throughput = new List <double>(); NLoad.Test <TestMock>() .WithNumberOfThreads(1) .WithDurationOf(TimeSpan.FromSeconds(2)) .OnHeartbeat((s, hearbeat) => throughput.Add(hearbeat.Throughput)) .Build() .Run(); var last = throughput.Last(); throughput.Clear(); NLoad.Test <TestMock>() .WithNumberOfThreads(1) .WithDurationOf(TimeSpan.FromSeconds(1)) .OnHeartbeat((s, hearbeat) => throughput.Add(hearbeat.Throughput)) .Build() .Run(); var first = throughput.First(); Assert.AreNotEqual(first, last); }
public void MultithreadedLoadTest() { var duration = TimeSpan.FromSeconds(3); var loadTest = NLoad.Test <OneSecondDelayTest>() .WithNumberOfThreads(10) .WithDurationOf(duration) .WithDeleyBetweenThreadStart(TimeSpan.Zero) .Build(); var result = loadTest.Run(); Assert.AreNotEqual(0, result.TotalIterations); Assert.AreNotEqual(TimeSpan.Zero, result.TotalRuntime); Assert.IsTrue(result.TotalRuntime > duration); Assert.IsTrue(result.Heartbeat.Any()); Assert.IsTrue(result.MaxThroughput > 0); Assert.IsTrue(result.AverageThroughput > 0); Assert.IsTrue(result.MinResponseTime > TimeSpan.Zero); Assert.IsTrue(result.MaxResponseTime > TimeSpan.Zero); Assert.IsTrue(result.AverageResponseTime > TimeSpan.Zero); Assert.IsTrue(result.TestRuns.Any()); }
public void ShouldReportTotalErrors() { var result = NLoad.Test <FailedTest>() .WithNumberOfThreads(1) .WithDurationOf(TimeSpan.FromSeconds(1)) .Build() .Run(); Assert.AreEqual(result.TotalErrors, result.TotalIterations); }
private static void TestNumberOfIterations(int durationInSeconds, int numThreads) { var duration = TimeSpan.FromSeconds(durationInSeconds); var result = NLoad.Test <OneSecondDelayTest>() .WithNumberOfThreads(numThreads) .WithDurationOf(duration) .WithDeleyBetweenThreadStart(TimeSpan.Zero) .Build() .Run(); Assert.AreEqual(numThreads * durationInSeconds, result.TotalIterations); }
public void ActualNumberOfThreads() { const int numberOfThreads = 10; var loadTest = NLoad.Test <ThreadCounter>() .WithNumberOfThreads(numberOfThreads) .WithDurationOf(TimeSpan.Zero) .WithDeleyBetweenThreadStart(TimeSpan.Zero) .Build(); loadTest.Run(); Assert.AreEqual(numberOfThreads, ThreadCounter.Count); }
public void HeartbeatCountEqualsDurationInSeconds() { for (var durationInSeconds = 1; durationInSeconds < 3; durationInSeconds++) { var duration = TimeSpan.FromSeconds(durationInSeconds); var result = NLoad.Test <TestMock>() .WithNumberOfThreads(1) .WithDurationOf(duration) .WithDeleyBetweenThreadStart(TimeSpan.Zero) .Build() .Run(); Assert.AreEqual(durationInSeconds, result.Heartbeat.Count - 1); } }
public void SubscribeToHeartbeatEvent() { var eventFired = false; NLoad.Test <TestMock>() .WithNumberOfThreads(1) .WithDurationOf(TimeSpan.FromSeconds(1)) .OnHeartbeat((s, hearbeat) => { eventFired = true; }) .Build() .Run(); Assert.IsTrue(eventFired); }
private Task <LoadTestResult> RunLoadTest() { var progress = _progress as IProgress <Heartbeat>; return(Task.Run(() => { var loadTest = NLoad.Test(_viewModel.SelectedTestType) .WithNumberOfThreads(_viewModel.Configuration.NumberOfThreads) .WithDurationOf(_viewModel.Configuration.Duration) .WithDeleyBetweenThreadStart(_viewModel.Configuration.DelayBetweenThreadStart) .WithCancellationToken(_cancellationTokenSource.Token) .OnHeartbeat((s, e) => progress.Report(e)) .Build(); return loadTest.Run(); }, _cancellationTokenSource.Token)); }
static void Main() { var loadTest = NLoad.Test <MyTest>() .WithNumberOfThreads(10) .WithDurationOf(TimeSpan.FromSeconds(10)) .OnHeartbeat((s, e) => Console.WriteLine("Threads: {0} Throughput: {1}", e.TotalThreads, e.Throughput)) .Build(); var result = loadTest.Run(); Console.WriteLine("\nTotal TotalIterations: {0}", result.TotalIterations); Console.WriteLine("Total Runtime: {0}", result.TotalRuntime); Console.WriteLine("Average Throughput: {0}", result.AverageThroughput); Console.WriteLine("Average Response Time: {0}", result.AverageResponseTime); Console.WriteLine("\nPress <Enter> to terminate."); Console.ReadLine(); }
public void VerifyLoadTestConfiguration() { const int numberOfThreads = 1; var duration = TimeSpan.FromSeconds(1); var delayBetweenThreadStart = TimeSpan.FromMilliseconds(100); var loadTest = NLoad.Test <TestMock>() .WithNumberOfThreads(numberOfThreads) .WithDurationOf(duration) .WithDeleyBetweenThreadStart(delayBetweenThreadStart) .Build(); var configuration = loadTest.Configuration; Assert.IsNotNull(configuration); Assert.AreEqual(numberOfThreads, configuration.NumberOfThreads); Assert.AreEqual(duration, configuration.Duration); Assert.AreEqual(delayBetweenThreadStart, configuration.DelayBetweenThreadStart); }
private static async Task <LoadTestResult> RunLoadTestAsync(IProgress <Heartbeat> progress) { var task = await Task.Run(() => { Debug.WriteLine("Start Run"); Debug.WriteLine("Task Id: {0}", Task.CurrentId); Debug.WriteLine("Thread Id: {0}", Thread.CurrentThread.ManagedThreadId); var result = NLoad.Test <TestMock>() .WithNumberOfThreads(1) .WithDurationOf(TimeSpan.FromSeconds(2)) .OnHeartbeat((s, e) => progress.Report(e)) .Build() .Run(); Debug.WriteLine("End Run"); Debug.WriteLine("Task Id: {0}", Task.CurrentId); Debug.WriteLine("Thread Id: {0}", Thread.CurrentThread.ManagedThreadId); return(result); }); return(task); }