Some sqlite_orm related fixes

pull/1312/head
Stephen Shelton 4 years ago
parent 98171aad36
commit a30806b375
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -29,8 +29,8 @@ namespace llarp
make_column("numDistinctRCsReceived", &PeerStats::numDistinctRCsReceived),
make_column("numLateRCs", &PeerStats::numLateRCs),
make_column("peakBandwidthBytesPerSec", &PeerStats::peakBandwidthBytesPerSec),
make_column("longestRCReceiveInterval", &PeerStats::longestRCReceiveIntervalMs),
make_column("mostExpiredRC", &PeerStats::mostExpiredRCMs)));
make_column("longestRCReceiveIntervalMs", &PeerStats::longestRCReceiveIntervalMs),
make_column("mostExpiredRCMs", &PeerStats::mostExpiredRCMs)));
}
using PeerDbStorage = decltype(initStorage(""));

@ -22,6 +22,7 @@ namespace llarp
fileString = file.value().native();
m_storage = std::make_unique<PeerDbStorage>(initStorage(fileString));
m_storage->sync_schema(true); // true for "preserve" as in "don't nuke" (how cute!)
}
void
@ -37,13 +38,13 @@ namespace llarp
copy = m_peerStats; // expensive deep copy
}
for (const auto& entry : m_peerStats)
for (const auto& entry : copy)
{
// call me paranoid...
assert(not entry.second.routerIdHex.empty());
assert(entry.first.ToHex() == entry.second.routerIdHex);
m_storage->insert(entry.second);
m_storage->replace(entry.second);
}
}

@ -1,11 +1,12 @@
#include <numeric>
#include <peerstats/peer_db.hpp>
#include <test_util.hpp>
#include <numeric>
#include <catch2/catch.hpp>
TEST_CASE("Test PeerDb PeerStats memory storage", "[PeerDb]")
{
const llarp::RouterID id = {};
const llarp::RouterID id = llarp::test::makeBuf<llarp::RouterID>(0x01);
const llarp::PeerStats empty(id);
llarp::PeerDb db;
@ -43,7 +44,7 @@ TEST_CASE("Test PeerDb load twice", "[PeerDb]")
TEST_CASE("Test PeerDb nukes stats on load", "[PeerDb]")
{
const llarp::RouterID id = {};
const llarp::RouterID id = llarp::test::makeBuf<llarp::RouterID>(0x01);
llarp::PeerDb db;
@ -62,9 +63,9 @@ TEST_CASE("Test PeerDb nukes stats on load", "[PeerDb]")
TEST_CASE("Test file-backed database", "[PeerDb]")
{
llarp::PeerDb db;
db.loadDatabase(std::nullopt);
db.loadDatabase("/tmp/peerdb_test_tmp.db.sqlite");
const llarp::RouterID id = {};
const llarp::RouterID id = llarp::test::makeBuf<llarp::RouterID>(0x01);
llarp::PeerStats stats(id);
stats.numConnectionAttempts = 42;

Loading…
Cancel
Save