Beispiel #1
0
        public void Start(DateTime startTime, TimeSpan duration)
        {
            var running = true;

            var start = DateTime.UtcNow;

            Heartbeats = new List<Heartbeat>();

            while (running)
            {
                CancellationToken.ThrowIfCancellationRequested();

                var now = DateTime.UtcNow;

                var runtime = now - start;

                var iterations = _loadTest.TotalIterations;

                var throughput = iterations / runtime.TotalSeconds;

                if (double.IsNaN(throughput) || double.IsInfinity(throughput)) continue;

                var heartbeat = new Heartbeat
                {
                    Timestamp = now,
                    Runtime = runtime,
                    TotalRuntime = DateTime.Now - startTime,
                    Throughput = throughput,
                    TotalIterations = iterations,
                    TotalErrors = _loadTest.TotalErrors,
                    TotalThreads = _loadTest.TotalThreads
                };

                Heartbeats.Add(heartbeat);

                OnHeartbeat(heartbeat);

                if (runtime >= duration)
                {
                    running = false;
                }
                else if (DateTime.UtcNow - start < duration)
                {
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #2
0
        private void OnHeartbeat(Heartbeat heartbeat)
        {
            var handler = Heartbeat;

            if (handler != null)
            {
                handler(this, heartbeat); //todo: add try catch?
            }
        }