From 68ee57a6a70bb5904e35eb9f74877432cde4b488 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Fri, 17 Apr 2020 10:09:52 -0700 Subject: [PATCH] fix ixbots unittest --- ixbots/ixbots/IXCobraBot.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ixbots/ixbots/IXCobraBot.cpp b/ixbots/ixbots/IXCobraBot.cpp index b91319a2..ffd8fdba 100644 --- a/ixbots/ixbots/IXCobraBot.cpp +++ b/ixbots/ixbots/IXCobraBot.cpp @@ -36,23 +36,38 @@ namespace ix std::atomic receivedCount(0); std::atomic sentCountTotal(0); std::atomic receivedCountTotal(0); + std::atomic sentCountPerSecs(0); + std::atomic receivedCountPerSecs(0); std::atomic stop(false); std::atomic throttled(false); std::atomic fatalCobraError(false); QueueManager queueManager(maxQueueSize); - auto timer = [&sentCount, &receivedCount, &sentCountTotal, &receivedCountTotal, &stop] { + auto timer = [&sentCount, + &receivedCount, + &sentCountTotal, + &receivedCountTotal, + &sentCountPerSecs, + &receivedCountPerSecs, + &stop] { while (!stop) { + // + // We cannot write to sentCount and receivedCount + // as those are used externally, so we need to introduce + // our own counters + // spdlog::info("messages received {} {} sent {} {}", - receivedCount, receivedCountTotal, sentCount, sentCountTotal); + receivedCountPerSecs, + receivedCountTotal, + sentCountPerSecs, + sentCountTotal); + receivedCountPerSecs = receivedCount - receivedCountTotal; + sentCountPerSecs = sentCount - receivedCountTotal; - receivedCountTotal += receivedCount; - sentCountTotal += sentCount; - - receivedCount = 0; - sentCount = 0; + receivedCountTotal += receivedCountPerSecs; + sentCountTotal += sentCountPerSecs; auto duration = std::chrono::seconds(1); std::this_thread::sleep_for(duration);