From 5f01bf5ea842cf930b2c9b4102959d8735e80982 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 15 Feb 2018 11:39:55 -0500 Subject: [PATCH] Fix up relay unit tests. Detected an unintentional bug benign behavior change. --- .vscode/launch.json | 2 +- src/lib/md/test/md2_tests.cpp | 49 +++++++++++++++++------------------ 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 48cc8f9d0..6b180437d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -106,7 +106,7 @@ "type": "cppdbg", "request": "launch", "program": "/home/bts/spark/build/ninja_debug/src/server/sparkd/sparkd", - "args": ["test", "-a", "Co2Tests"], + "args": ["test", "-a", "Co2RelayTests"], "stopAtEntry": false, "cwd": "/home/bts/spark/build/ninja_debug/src/server/sparkd/", "environment": [], diff --git a/src/lib/md/test/md2_tests.cpp b/src/lib/md/test/md2_tests.cpp index 30f7c8fee..4d44ac1ab 100644 --- a/src/lib/md/test/md2_tests.cpp +++ b/src/lib/md/test/md2_tests.cpp @@ -32,6 +32,8 @@ using namespace std; namespace bts { int md_tests = 0; namespace md { +// import this from RelayClient.cpp +PriceSize book_at(const google::protobuf::RepeatedPtrField& side, int index); namespace test { using namespace api; @@ -1200,14 +1202,14 @@ TEST_CASE ("Co2IndexTests","[md]") { struct Co2RelayTests { void setup() { - config::internal::initialize_for_test( - "PlatformMap {" - " value {" - " sim {" - " exchange: TESTEXCHANGE" - " }" - " }" - "}"); + // config::internal::initialize_for_test( + // "PlatformMap {" + // " value {" + // " sim {" + // " exchange: TESTEXCHANGE" + // " }" + // " }" + // "}"); } void teardown() {} @@ -1231,9 +1233,9 @@ struct Co2RelayTests { return temp; } - PriceSize convert(const co2::PriceSizeMessage& psm) { - return PriceSize(psm.mantissa(), psm.exponent(), psm.size()); - } + // PriceSize convert(const co2::PriceSizeMessage& psm) { + // return PriceSize(psm.mantissa(), psm.exponent(), psm.size()); + // } void relay_nans() { MDProducer producer(TEST_PLATFORM); @@ -1284,8 +1286,8 @@ struct Co2RelayTests { REQUIRE(update.has_book()); REQUIRE(update.book().asks_size() > 0); REQUIRE(update.book().bids_size() > 0); - REQUIRE(convert(update.book().bids(0)) == price35); - REQUIRE(convert(update.book().asks(0)) == price35); + REQUIRE(book_at(update.book().bids(), 0) == price35); + REQUIRE(book_at(update.book().asks(), 0) == price35); } // Second request with updated time should include nothing @@ -1305,8 +1307,8 @@ struct Co2RelayTests { REQUIRE(reply.channels().size() == 1); REQUIRE(reply.channels(0).updates().size() == 1); REQUIRE(reply.channels(0).updates(0).has_book()); - REQUIRE(convert(reply.channels(0).updates(0).book().bids(0)) == price5); - REQUIRE(convert(reply.channels(0).updates(0).book().asks(0)) == price5); + REQUIRE(book_at(reply.channels(0).updates(0).book().bids(), 0) == price5); + REQUIRE(book_at(reply.channels(0).updates(0).book().asks(), 0) == price5); // NaN out all the prices - expect to get a full set of updates for(auto p : producers) { @@ -1320,10 +1322,9 @@ struct Co2RelayTests { REQUIRE((size_t)reply.channels(0).updates().size() == producers.size()); for (auto& update : reply.channels(0).updates()) { REQUIRE(update.has_book()); - REQUIRE(update.book().bids_size() > 0); - REQUIRE(update.book().asks_size() > 0); - REQUIRE(convert(update.book().bids(0)) == PriceSize::NO_MARKET); - REQUIRE(convert(update.book().asks(0)) == PriceSize::NO_MARKET); + // We need to have a book to signal that it was updated but it can have no rows. This signifies an empty book and will be written as such by the relay client. + REQUIRE(book_at(update.book().bids(), 0) == PriceSize::NO_MARKET); + REQUIRE(book_at(update.book().asks(), 0) == PriceSize::NO_MARKET); } // Fill up the markets again @@ -1340,8 +1341,8 @@ struct Co2RelayTests { REQUIRE(update.has_book()); REQUIRE(update.book().bids_size() > 0); REQUIRE(update.book().asks_size() > 0); - REQUIRE(convert(update.book().bids(0)) == price35); - REQUIRE(convert(update.book().asks(0)) == price35); + REQUIRE(book_at(update.book().bids(), 0) == price35); + REQUIRE(book_at(update.book().asks(), 0) == price35); } // NaN out the bids @@ -1356,10 +1357,8 @@ struct Co2RelayTests { REQUIRE((size_t)reply.channels(0).updates().size() == producers.size()); for (auto& update : reply.channels(0).updates()) { REQUIRE(update.has_book()); - REQUIRE(update.book().bids_size() > 0); - REQUIRE(update.book().asks_size() > 0); - REQUIRE(convert(update.book().bids(0)) == PriceSize::NO_MARKET); - REQUIRE(convert(update.book().asks(0)) == price35); + REQUIRE(book_at(update.book().bids(), 0) == PriceSize::NO_MARKET); + REQUIRE(book_at(update.book().asks(), 0) == price35); } } } ;