namespace chaos {
constexpr std::string_view kSelectSmallTimeout = "select-small-timeout";
constexpr std::string_view kPortalSmallTimeout = "portal-small-timeout";
"SELECT generate_series(1, 100)",
};
constexpr int kPortalChunkSize = 4;
"SELECT generate_series(1, 10)",
};
public:
static constexpr std::string_view kName = "handler-chaos-postgres";
std::string HandleRequestThrow(
private:
};
: HttpHandlerBase(config, context),
pg_cluster_(
std::string PostgresHandler::HandleRequestThrow(
const auto& type = request.
GetArg(
"type");
if (type.empty()) {
}
const auto& sleep_ms = request.
GetArg(
"sleep_ms");
if (!sleep_ms.empty()) {
LOG_DEBUG() <<
"Sleep for " << sleep_ms <<
"ms";
}
if (type == "select" || type == kSelectSmallTimeout) {
const std::chrono::milliseconds timeout{
type == kSelectSmallTimeout ? 800 : 30000};
auto transaction =
transaction.Execute(cc, kSelectMany);
transaction.Commit();
return "OK!";
} else if (type == "portal" || type == kPortalSmallTimeout) {
const std::chrono::seconds timeout{type == kPortalSmallTimeout ? 3 : 25};
auto transaction =
auto portal = transaction.MakePortal(cc, kPortalQuery);
std::vector<int> result;
while (portal) {
auto res = portal.Fetch(kPortalChunkSize);
auto vec = res.AsContainer<std::vector<int>>();
result.insert(result.end(), vec.begin(), vec.end());
}
transaction.Commit();
return fmt::format("[{}]", fmt::join(result, ", "));
} else {
fmt::format("Unknown chaos test request type '{}'", type));
}
}
}
int main(int argc, char* argv[]) {
const auto component_list =
.Append<components::DynamicConfigClientUpdater>()
.Append<chaos::PostgresHandler>()
.Append<components::HttpClient>()
.Append<components::TestsuiteSupport>()
.Append<clients::dns::Component>();
}