mirror of
https://github.com/gabime/spdlog.git
synced 2024-11-21 03:12:41 +08:00
Fixed mpmc_q test for osx in travis
This commit is contained in:
parent
a281d21fbf
commit
9ad9cfb898
@ -84,8 +84,6 @@ matrix:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
before_script:
|
||||
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
|
||||
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#define SPDLOG_TRACE_ON
|
||||
|
@ -2,25 +2,27 @@
|
||||
|
||||
using namespace std::chrono;
|
||||
using std::chrono::milliseconds;
|
||||
using std::chrono::system_clock;
|
||||
using test_clock = std::chrono::high_resolution_clock ;
|
||||
|
||||
system_clock::time_point now_millis()
|
||||
|
||||
static milliseconds millis_from(const test_clock::time_point &tp0)
|
||||
{
|
||||
return time_point_cast<milliseconds>(system_clock::now());
|
||||
return std::chrono::duration_cast<milliseconds>(test_clock::now()-tp0);
|
||||
}
|
||||
TEST_CASE("dequeue-empty-nowait", "[mpmc_blocking_q]")
|
||||
{
|
||||
size_t q_size = 100;
|
||||
milliseconds tolerance_wait(10);
|
||||
milliseconds tolerance_wait(30);
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
int popped_item;
|
||||
|
||||
auto millis_0 = now_millis();
|
||||
auto start = test_clock::now();
|
||||
auto rv = q.dequeue_for(popped_item, milliseconds::zero());
|
||||
auto millis_1 = now_millis();
|
||||
auto delta_ms = millis_from(start);
|
||||
|
||||
REQUIRE(rv == false);
|
||||
REQUIRE((millis_1 - millis_0) <= tolerance_wait);
|
||||
INFO("Delta " << delta_ms.count() << " millis");
|
||||
REQUIRE(delta_ms <= tolerance_wait);
|
||||
}
|
||||
|
||||
TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]")
|
||||
@ -28,16 +30,17 @@ TEST_CASE("dequeue-empty-wait", "[mpmc_blocking_q]")
|
||||
|
||||
size_t q_size = 100;
|
||||
milliseconds wait_ms(250);
|
||||
milliseconds tolerance_wait(10);
|
||||
milliseconds tolerance_wait(30);
|
||||
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
int popped_item;
|
||||
auto millis_0 = now_millis();
|
||||
auto start = test_clock::now();
|
||||
auto rv = q.dequeue_for(popped_item, wait_ms);
|
||||
auto millis_1 = now_millis();
|
||||
auto delta_ms = millis_1 - millis_0;
|
||||
auto delta_ms = millis_from(start);
|
||||
|
||||
REQUIRE(rv == false);
|
||||
|
||||
INFO("Delta " << delta_ms.count() << " millis");
|
||||
REQUIRE(delta_ms >= wait_ms);
|
||||
REQUIRE(delta_ms <= wait_ms + tolerance_wait);
|
||||
}
|
||||
@ -47,15 +50,17 @@ TEST_CASE("enqueue_nowait", "[mpmc_blocking_q]")
|
||||
|
||||
size_t q_size = 1;
|
||||
spdlog::details::mpmc_blocking_queue<int> q(q_size);
|
||||
milliseconds tolerance_wait(10);
|
||||
milliseconds tolerance_wait(30);
|
||||
|
||||
q.enqueue(1);
|
||||
REQUIRE(q.overrun_counter() == 0);
|
||||
|
||||
auto millis_0 = now_millis();
|
||||
auto start = test_clock::now();
|
||||
q.enqueue_nowait(2);
|
||||
auto millis_1 = now_millis();
|
||||
REQUIRE((millis_1 - millis_0) <= tolerance_wait);
|
||||
auto delta_ms = millis_from(start);
|
||||
|
||||
INFO("Delta " << delta_ms.count() << " millis");
|
||||
REQUIRE(delta_ms <= tolerance_wait);
|
||||
REQUIRE(q.overrun_counter() == 1);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user