Add cache test (#807)

Fixes #809
This commit is contained in:
cyan317
2023-08-03 15:03:17 +01:00
committed by GitHub
parent c90bc15959
commit 111b55b397
5 changed files with 252 additions and 17 deletions

View File

@@ -123,13 +123,14 @@ struct AsyncAsioContextTest : virtual public NoLoggerFixture
AsyncAsioContextTest()
{
work.emplace(ctx); // make sure ctx does not stop on its own
runner.emplace([&] { ctx.run(); });
}
~AsyncAsioContextTest()
{
work.reset();
if (runner.joinable())
runner.join();
if (runner->joinable())
runner->join();
ctx.stop();
}
@@ -137,9 +138,9 @@ struct AsyncAsioContextTest : virtual public NoLoggerFixture
stop()
{
work.reset();
if (runner->joinable())
runner->join();
ctx.stop();
if (runner.joinable())
runner.join();
}
protected:
@@ -147,7 +148,7 @@ protected:
private:
std::optional<boost::asio::io_service::work> work;
std::thread runner{[this] { ctx.run(); }};
std::optional<std::thread> runner;
};
/**

View File

@@ -0,0 +1,49 @@
//------------------------------------------------------------------------------
/*
This file is part of clio: https://github.com/XRPLF/clio
Copyright (c) 2023, the clio developers.
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#pragma once
#include <backend/Types.h>
#include <gmock/gmock.h>
struct MockCache
{
MOCK_METHOD(void, update, (std::vector<Backend::LedgerObject> const& a, uint32_t b, bool c), ());
MOCK_METHOD(std::optional<Backend::Blob>, get, (ripple::uint256 const& a, uint32_t b), (const));
MOCK_METHOD(std::optional<Backend::LedgerObject>, getSuccessor, (ripple::uint256 const& a, uint32_t b), (const));
MOCK_METHOD(std::optional<Backend::LedgerObject>, getPredecessor, (ripple::uint256 const& a, uint32_t b), (const));
MOCK_METHOD(void, setDisabled, (), ());
MOCK_METHOD(void, setFull, (), ());
MOCK_METHOD(bool, isFull, (), (const));
MOCK_METHOD(uint32_t, latestLedgerSequence, (), (const));
MOCK_METHOD(size_t, size, (), (const));
MOCK_METHOD(float, getObjectHitRate, (), (const));
MOCK_METHOD(float, getSuccessorHitRate, (), (const));
};