chore: No ALL_CAPS (#1760)

Fixes #1680
This commit is contained in:
Alex Kremer
2025-01-02 11:39:31 +00:00
committed by GitHub
parent efe5d08205
commit 820b32c6d7
361 changed files with 10061 additions and 9724 deletions

View File

@@ -92,14 +92,14 @@ protected:
MOCK_METHOD(boost::json::object, report, (), ());
};
MockHandle handle{};
MockBackendCounters::PtrType counters = MockBackendCounters::make();
static constexpr auto NUM_STATEMENTS = 3u;
MockHandle handle_{};
MockBackendCounters::PtrType counters_ = MockBackendCounters::make();
static constexpr auto kNUM_STATEMENTS = 3u;
DefaultExecutionStrategy<MockHandle, MockBackendCounters>
makeStrategy(Settings s = {})
{
return DefaultExecutionStrategy<MockHandle, MockBackendCounters>(s, handle, counters);
return DefaultExecutionStrategy<MockHandle, MockBackendCounters>(s, handle_, counters_);
}
};
@@ -107,7 +107,7 @@ TEST_F(BackendCassandraExecutionStrategyTest, IsTooBusy)
{
{
auto strat = makeStrategy(Settings{.maxReadRequestsOutstanding = 0});
EXPECT_CALL(*counters, registerTooBusy());
EXPECT_CALL(*counters_, registerTooBusy());
EXPECT_TRUE(strat.isTooBusy());
}
auto strat = makeStrategy(Settings{.maxReadRequestsOutstanding = 1});
@@ -118,15 +118,15 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadOneInCoroutineSuccessful)
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([](auto const& /* statement */, auto&& cb) {
cb({}); // pretend we got data
return FakeFutureWithCallback{};
});
EXPECT_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
EXPECT_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(1));
EXPECT_CALL(*counters, registerReadFinishedImpl(testing::_, 1));
EXPECT_CALL(*counters_, registerReadStartedImpl(1));
EXPECT_CALL(*counters_, registerReadFinishedImpl(testing::_, 1));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statement = FakeStatement{};
@@ -138,16 +138,16 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadOneInCoroutineThrowsOnTimeoutF
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([](auto const&, auto&& cb) {
auto res = FakeResultOrError{CassandraError{"timeout", CASS_ERROR_LIB_REQUEST_TIMED_OUT}};
cb(res); // notify that item is ready
return FakeFutureWithCallback{res};
});
EXPECT_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
EXPECT_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(1));
EXPECT_CALL(*counters, registerReadErrorImpl(1));
EXPECT_CALL(*counters_, registerReadStartedImpl(1));
EXPECT_CALL(*counters_, registerReadErrorImpl(1));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statement = FakeStatement{};
@@ -159,16 +159,16 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadOneInCoroutineThrowsOnInvalidQ
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([](auto const&, auto&& cb) {
auto res = FakeResultOrError{CassandraError{"invalid", CASS_ERROR_SERVER_INVALID_QUERY}};
cb(res); // notify that item is ready
return FakeFutureWithCallback{res};
});
EXPECT_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
EXPECT_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(1));
EXPECT_CALL(*counters, registerReadErrorImpl(1));
EXPECT_CALL(*counters_, registerReadStartedImpl(1));
EXPECT_CALL(*counters_, registerReadErrorImpl(1));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statement = FakeStatement{};
@@ -180,21 +180,23 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineSuccessful)
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.WillByDefault([](auto const& statements, auto&& cb) {
EXPECT_EQ(statements.size(), NUM_STATEMENTS);
EXPECT_EQ(statements.size(), kNUM_STATEMENTS);
cb({}); // pretend we got data
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(testing::_, NUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadFinishedImpl(testing::_, kNUM_STATEMENTS));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
strat.read(yield, statements);
});
}
@@ -203,22 +205,24 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineThrowsOnTimeou
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.WillByDefault([](auto const& statements, auto&& cb) {
EXPECT_EQ(statements.size(), NUM_STATEMENTS);
EXPECT_EQ(statements.size(), kNUM_STATEMENTS);
auto res = FakeResultOrError{CassandraError{"timeout", CASS_ERROR_LIB_REQUEST_TIMED_OUT}};
cb(res); // notify that item is ready
return FakeFutureWithCallback{res};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadErrorImpl(kNUM_STATEMENTS));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
EXPECT_THROW(strat.read(yield, statements), data::DatabaseTimeout);
});
}
@@ -227,22 +231,24 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineThrowsOnInvali
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.WillByDefault([](auto const& statements, auto&& cb) {
EXPECT_EQ(statements.size(), NUM_STATEMENTS);
EXPECT_EQ(statements.size(), kNUM_STATEMENTS);
auto res = FakeResultOrError{CassandraError{"invalid", CASS_ERROR_SERVER_INVALID_QUERY}};
cb(res); // notify that item is ready
return FakeFutureWithCallback{res};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadErrorImpl(kNUM_STATEMENTS));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
EXPECT_THROW(strat.read(yield, statements), std::runtime_error);
});
}
@@ -251,25 +257,27 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadBatchInCoroutineMarksBusyIfReq
{
auto strat = makeStrategy(Settings{.maxReadRequestsOutstanding = 2});
ON_CALL(handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.WillByDefault([this, &strat](auto const& statements, auto&& cb) {
EXPECT_EQ(statements.size(), NUM_STATEMENTS);
EXPECT_CALL(*counters, registerTooBusy());
EXPECT_EQ(statements.size(), kNUM_STATEMENTS);
EXPECT_CALL(*counters_, registerTooBusy());
EXPECT_TRUE(strat.isTooBusy()); // 2 was the limit, we sent 3
cb({}); // notify that item is ready
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.Times(1);
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(testing::_, NUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadFinishedImpl(testing::_, kNUM_STATEMENTS));
runSpawn([&strat](boost::asio::yield_context yield) {
EXPECT_FALSE(strat.isTooBusy()); // 2 was the limit, 0 atm
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
strat.read(yield, statements);
EXPECT_FALSE(strat.isTooBusy()); // after read completes it's 0 again
});
@@ -279,24 +287,24 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineSuccessful)
{
auto strat = makeStrategy();
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([](auto const&, auto&& cb) {
cb({}); // pretend we got data
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle,
handle_,
asyncExecute(
A<FakeStatement const&>(),
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(NUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadFinishedImpl(testing::_, NUM_STATEMENTS));
.Times(kNUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadFinishedImpl(testing::_, kNUM_STATEMENTS));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
auto res = strat.readEach(yield, statements);
EXPECT_EQ(res.size(), statements.size());
});
@@ -307,7 +315,7 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineThrowsOnFailure
auto strat = makeStrategy();
auto callCount = std::atomic_int{0};
ON_CALL(handle, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(handle_, asyncExecute(A<FakeStatement const&>(), A<std::function<void(FakeResultOrError)>&&>()))
.WillByDefault([&callCount](auto const&, auto&& cb) {
if (callCount == 1) { // error happens on one of the entries
cb({CassandraError{"invalid data", CASS_ERROR_LIB_INVALID_DATA}});
@@ -318,19 +326,19 @@ TEST_F(BackendCassandraExecutionStrategyTest, ReadEachInCoroutineThrowsOnFailure
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle,
handle_,
asyncExecute(
A<FakeStatement const&>(),
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(NUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters, registerReadStartedImpl(NUM_STATEMENTS));
EXPECT_CALL(*counters, registerReadErrorImpl(1));
EXPECT_CALL(*counters, registerReadFinishedImpl(testing::_, 2));
.Times(kNUM_STATEMENTS); // once per statement
EXPECT_CALL(*counters_, registerReadStartedImpl(kNUM_STATEMENTS));
EXPECT_CALL(*counters_, registerReadErrorImpl(1));
EXPECT_CALL(*counters_, registerReadFinishedImpl(testing::_, 2));
runSpawn([&strat](boost::asio::yield_context yield) {
auto statements = std::vector<FakeStatement>(NUM_STATEMENTS);
auto statements = std::vector<FakeStatement>(kNUM_STATEMENTS);
EXPECT_THROW(strat.readEach(yield, statements), data::DatabaseTimeout);
});
}
@@ -339,10 +347,10 @@ TEST_F(BackendCassandraExecutionStrategyTest, WriteSyncFirstTrySuccessful)
{
auto strat = makeStrategy();
ON_CALL(handle, execute(A<FakeStatement const&>())).WillByDefault([](auto const&) { return FakeResultOrError{}; });
EXPECT_CALL(handle,
ON_CALL(handle_, execute(A<FakeStatement const&>())).WillByDefault([](auto const&) { return FakeResultOrError{}; });
EXPECT_CALL(handle_,
execute(A<FakeStatement const&>())).Times(1); // first one will succeed
EXPECT_CALL(*counters, registerWriteSync(testing::_));
EXPECT_CALL(*counters_, registerWriteSync(testing::_));
EXPECT_TRUE(strat.writeSync({}));
}
@@ -352,15 +360,15 @@ TEST_F(BackendCassandraExecutionStrategyTest, WriteSyncRetrySuccessful)
auto strat = makeStrategy();
auto callCount = 0;
ON_CALL(handle, execute(A<FakeStatement const&>())).WillByDefault([&callCount](auto const&) {
ON_CALL(handle_, execute(A<FakeStatement const&>())).WillByDefault([&callCount](auto const&) {
if (callCount++ == 1)
return FakeResultOrError{};
return FakeResultOrError{CassandraError{"invalid data", CASS_ERROR_LIB_INVALID_DATA}};
});
EXPECT_CALL(handle,
EXPECT_CALL(handle_,
execute(A<FakeStatement const&>())).Times(2); // first one will fail, second will succeed
EXPECT_CALL(*counters, registerWriteSyncRetry());
EXPECT_CALL(*counters, registerWriteSync(testing::_));
EXPECT_CALL(*counters_, registerWriteSyncRetry());
EXPECT_CALL(*counters_, registerWriteSync(testing::_));
EXPECT_TRUE(strat.writeSync({}));
}
@@ -371,28 +379,30 @@ TEST_F(BackendCassandraExecutionStrategyTest, WriteMultipleAndCallSyncSucceeds)
auto const totalRequests = 1024u;
auto callCount = std::atomic_uint{0u};
auto work = std::optional<boost::asio::io_context::work>{ctx};
auto thread = std::thread{[this]() { ctx.run(); }};
auto work = std::optional<boost::asio::io_context::work>{ctx_};
auto thread = std::thread{[this]() { ctx_.run(); }};
ON_CALL(handle, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>()))
ON_CALL(
handle_, asyncExecute(A<std::vector<FakeStatement> const&>(), A<std::function<void(FakeResultOrError)>&&>())
)
.WillByDefault([this, &callCount](auto const&, auto&& cb) {
// run on thread to emulate concurrency model of real asyncExecute
boost::asio::post(ctx, [&callCount, cb = std::forward<decltype(cb)>(cb)] {
boost::asio::post(ctx_, [&callCount, cb = std::forward<decltype(cb)>(cb)] {
++callCount;
cb({}); // pretend we got data
});
return FakeFutureWithCallback{};
});
EXPECT_CALL(
handle,
handle_,
asyncExecute(
A<std::vector<FakeStatement> const&>(),
A<std::function<void(FakeResultOrError)>&&>()
)
)
.Times(totalRequests); // one per write call
EXPECT_CALL(*counters, registerWriteStarted()).Times(totalRequests);
EXPECT_CALL(*counters, registerWriteFinished(testing::_)).Times(totalRequests);
EXPECT_CALL(*counters_, registerWriteStarted()).Times(totalRequests);
EXPECT_CALL(*counters_, registerWriteFinished(testing::_)).Times(totalRequests);
auto makeStatements = [] { return std::vector<FakeStatement>(16); };
for (auto i = 0u; i < totalRequests; ++i)
@@ -408,6 +418,6 @@ TEST_F(BackendCassandraExecutionStrategyTest, WriteMultipleAndCallSyncSucceeds)
TEST_F(BackendCassandraExecutionStrategyTest, StatsCallsCountersReport)
{
auto strat = makeStrategy();
EXPECT_CALL(*counters, report());
EXPECT_CALL(*counters_, report());
strat.stats();
}