#include <fmt/format.h>
#include <fmt/ranges.h>
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";
const override;
private:
};
: HttpHandlerBase(config, context),
std::string
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 = pg_cluster_->Begin(
);
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 = pg_cluster_->Begin(
);
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 {
UINVARIANT(
false, fmt::format(
"Unknown chaos test request type '{}'", type));
}
}
}
int main(int argc, char* argv[]) {
.Append<components::DynamicConfigClientUpdater>()
.Append<chaos::PostgresHandler>()
.Append<components::HttpClient>()
.Append<components::TestsuiteSupport>()
.Append<clients::dns::Component>();
}