|
|
@@ -192,4 +192,77 @@ TEST(DbErrors, ARateLimitFromTheDatabaseIsA429SoItCanCarryRetryAfter) {
|
|
|
EXPECT_EQ(svapi::httpStatus(a.code), 429);
|
|
|
}
|
|
|
|
|
|
+// --- ResourceExhausted covers three unrelated refusals (database 2.13.0) ----
|
|
|
+
|
|
|
+TEST(DbErrors, AnOversizedMessageIs422NotAWaitAndRetry429) {
|
|
|
+ // The whole point: 429 tells a caller to wait, and no amount of waiting
|
|
|
+ // shrinks a payload. The database classifies the size case itself from
|
|
|
+ // 2.13.0, so we branch on the reason rather than on gRPC's wording.
|
|
|
+ const svapi::ApiError e =
|
|
|
+ svapi::apiErrorFor(detail(Code::ResourceExhausted, "message_too_large",
|
|
|
+ "Sent message larger than max (105906234 vs. 104857600)"));
|
|
|
+ EXPECT_EQ(svapi::httpStatus(e.code), 422);
|
|
|
+ EXPECT_EQ(e.slug, "message_too_large");
|
|
|
+ // The database's sentence carries both sizes AND the direction, so it must
|
|
|
+ // reach the caller rather than being replaced by wording of our own.
|
|
|
+ EXPECT_NE(std::string(e.what()).find("104857600"), std::string::npos);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DbErrors, AGenuineRateLimitStillWaits) {
|
|
|
+ // The other side of the branch: without that reason this is a real rate
|
|
|
+ // limit or memory pressure, where 429 and Retry-After are correct.
|
|
|
+ const svapi::ApiError e = svapi::apiErrorFor(detail(Code::ResourceExhausted, "",
|
|
|
+ "too many requests"));
|
|
|
+ EXPECT_EQ(svapi::httpStatus(e.code), 429);
|
|
|
+ EXPECT_EQ(e.slug, "rate_limited");
|
|
|
+ EXPECT_EQ(e.code, svapi::ErrCode::TooManyRequests)
|
|
|
+ << "the global handler keys Retry-After off this code";
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DbErrors, AnUnknownResourceExhaustedReasonKeepsTheBroaderAnswer) {
|
|
|
+ // A future reason we do not know must not be guessed into the narrow 422.
|
|
|
+ EXPECT_EQ(svapi::httpStatus(
|
|
|
+ svapi::apiErrorFor(detail(Code::ResourceExhausted, "something_new")).code),
|
|
|
+ 429);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DbErrors, TheSizeRefusalIsNotBlamedOnTheCallersBody) {
|
|
|
+ // Deliberately NOT `body_too_large`. The limit bites in either direction,
|
|
|
+ // and a stored row can exceed it without any single request doing so -
|
|
|
+ // repeated patches grow one until it cannot be read back, measured on a
|
|
|
+ // scratch server. So the caller may have sent nothing large at all.
|
|
|
+ const svapi::ApiError e =
|
|
|
+ svapi::apiErrorFor(detail(Code::ResourceExhausted, "message_too_large",
|
|
|
+ "Sent message larger than max (104857726 vs. 104857600)"));
|
|
|
+ EXPECT_NE(e.slug, "body_too_large")
|
|
|
+ << "a slug naming the caller's body misdirects them when it was the RESPONSE "
|
|
|
+ "that could not fit";
|
|
|
+ EXPECT_EQ(e.slug, "message_too_large");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DbErrors, MemoryPressureIsNotTheCallersFaultAndSaysSo) {
|
|
|
+ // The database's admission control refuses writes under memory pressure
|
|
|
+ // with this code and a stable reason. 429 and "wait" are right, but
|
|
|
+ // reporting it as `rate_limited` would tell a caller it is sending too
|
|
|
+ // much and have it throttle a client that was never the problem. Same
|
|
|
+ // reason `read_only` has its own slug while also meaning "wait".
|
|
|
+ const svapi::ApiError e = svapi::apiErrorFor(detail(Code::ResourceExhausted,
|
|
|
+ "memory_pressure", "under pressure"));
|
|
|
+ EXPECT_EQ(svapi::httpStatus(e.code), 429);
|
|
|
+ EXPECT_EQ(e.slug, "memory_pressure");
|
|
|
+ EXPECT_EQ(e.code, svapi::ErrCode::TooManyRequests)
|
|
|
+ << "must keep the code the global handler attaches Retry-After to";
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DbErrors, TheExportConcurrencyCapFallsInTheWaitArm) {
|
|
|
+ // The database's cap on simultaneous exports answers this code with NO
|
|
|
+ // reason, so it must land on the general "wait" answer rather than being
|
|
|
+ // mistaken for a size refusal. Asserted because the fallback arm is the
|
|
|
+ // one that quietly absorbs anything new.
|
|
|
+ const svapi::ApiError e =
|
|
|
+ svapi::apiErrorFor(detail(Code::ResourceExhausted, "", "too many concurrent exports"));
|
|
|
+ EXPECT_EQ(svapi::httpStatus(e.code), 429);
|
|
|
+ EXPECT_EQ(e.slug, "rate_limited");
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|