|
|
@@ -131,4 +131,53 @@ TEST(EmbedBudget, RoundsUpSoATimeLeftBudgetIsNotTruncatedToNothing) {
|
|
|
EXPECT_EQ(b.connectSec + b.readSec, 2);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+TEST(EmbedBudget, AMillisecondTimeoutBecomesAWholeSecond) {
|
|
|
+ // Reported from production as "embedTimeoutMs is ignored on store": a
|
|
|
+ // consumer passed 1 and watched a store SUCCEED, and separately measured a
|
|
|
+ // search 504 arriving after 1041 ms rather than 1 ms. Both are this floor,
|
|
|
+ // not a missing implementation. The HTTP client takes WHOLE SECONDS and
|
|
|
+ // treats 0 as "no timeout", so anything under a second can only become 1 -
|
|
|
+ // and a provider that answers inside that second legitimately succeeds.
|
|
|
+ //
|
|
|
+ // So a sub-second embedTimeoutMs does not do what its name suggests, and
|
|
|
+ // that has to be stated in the consumer docs rather than discovered.
|
|
|
+ svapi::functions::EmbedBudgetRequest in;
|
|
|
+ in.remainingBudgetMs = 60000;
|
|
|
+ in.callTimeoutMs = 1;
|
|
|
+ const auto out = svapi::functions::resolveEmbedBudget(in);
|
|
|
+ EXPECT_EQ(out.connectSec, 1);
|
|
|
+ EXPECT_EQ(out.readSec, 1);
|
|
|
+ EXPECT_TRUE(out.boundByCall) << "a 1 ms ask is still the binding constraint, so a failure "
|
|
|
+ "must be reported as the script's choice";
|
|
|
+ // The observable consequence: up to 2 s, which is what was measured.
|
|
|
+ EXPECT_LE(out.connectSec + out.readSec, 2);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbedBudget, EveryTimeoutUnderASecondCollapsesToTheSameThing) {
|
|
|
+ // 1 ms and 999 ms are indistinguishable, so a caller tuning inside that
|
|
|
+ // range is tuning nothing. Asserted across the range so nobody "fixes"
|
|
|
+ // this by making the floor depend on the value.
|
|
|
+ for (const int64_t ms : {1, 50, 250, 500, 750, 999}) {
|
|
|
+ svapi::functions::EmbedBudgetRequest in;
|
|
|
+ in.remainingBudgetMs = 60000;
|
|
|
+ in.callTimeoutMs = ms;
|
|
|
+ const auto out = svapi::functions::resolveEmbedBudget(in);
|
|
|
+ EXPECT_EQ(out.connectSec, 1) << ms;
|
|
|
+ EXPECT_EQ(out.readSec, 1) << ms;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbedBudget, AboveTheFloorTheAskIsActuallyHonoured) {
|
|
|
+ // The other half of the story: once the ask clears a second it does
|
|
|
+ // something, or the two tests above would be describing a dead option.
|
|
|
+ svapi::functions::EmbedBudgetRequest in;
|
|
|
+ in.remainingBudgetMs = 60000;
|
|
|
+ in.callTimeoutMs = 4000; // what the reporting consumer actually runs
|
|
|
+ const auto out = svapi::functions::resolveEmbedBudget(in);
|
|
|
+ EXPECT_LE(out.connectSec + out.readSec, 4);
|
|
|
+ EXPECT_GT(out.readSec, 1) << "a 4 s ask must buy more read time than a 1 ms one";
|
|
|
+ EXPECT_TRUE(out.boundByCall);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|