|
|
@@ -190,48 +190,205 @@ TEST(ProjectSettings, AnUnsetPolicyIsNotWrittenToStorage) {
|
|
|
EXPECT_FALSE(p.toJson().contains("default_function_policy"));
|
|
|
}
|
|
|
|
|
|
+// Per-project embedding timeouts. NARROWING ONLY, which is the whole property
|
|
|
+// worth testing: they govern a shared resource, so an override that could raise
|
|
|
+// them would let one tenant hold a provider connection - and the pooled runtime
|
|
|
+// waiting on it - for longer than the operator allowed.
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, NoOverrideInheritsTheGlobalValues) {
|
|
|
+ Settings g;
|
|
|
+ g.embeddingConnectTimeoutSec = 10;
|
|
|
+ g.embeddingReadTimeoutSec = 60;
|
|
|
+ const CollectionMeta none;
|
|
|
+ const ResolvedEmbedding r = resolveEmbedding(g, nullptr, none);
|
|
|
+ EXPECT_EQ(r.connectTimeoutSec, 10u);
|
|
|
+ EXPECT_EQ(r.readTimeoutSec, 60u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, AProjectCanTighten) {
|
|
|
+ Settings g;
|
|
|
+ g.embeddingConnectTimeoutSec = 10;
|
|
|
+ g.embeddingReadTimeoutSec = 60;
|
|
|
+ ProjectSettings p;
|
|
|
+ p.embeddingConnectTimeoutSec = 2;
|
|
|
+ p.embeddingReadTimeoutSec = 4;
|
|
|
+ const CollectionMeta none;
|
|
|
+ const ResolvedEmbedding r = resolveEmbedding(g, &p, none);
|
|
|
+ EXPECT_EQ(r.connectTimeoutSec, 2u);
|
|
|
+ EXPECT_EQ(r.readTimeoutSec, 4u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, AProjectCannotLoosen) {
|
|
|
+ // The property. A project asking for longer than the global allowance gets
|
|
|
+ // the global allowance, not its own request.
|
|
|
+ Settings g;
|
|
|
+ g.embeddingConnectTimeoutSec = 5;
|
|
|
+ g.embeddingReadTimeoutSec = 20;
|
|
|
+ ProjectSettings p;
|
|
|
+ p.embeddingConnectTimeoutSec = 600;
|
|
|
+ p.embeddingReadTimeoutSec = 600;
|
|
|
+ const CollectionMeta none;
|
|
|
+ const ResolvedEmbedding r = resolveEmbedding(g, &p, none);
|
|
|
+ EXPECT_EQ(r.connectTimeoutSec, 5u) << "a project must not be able to raise a shared limit";
|
|
|
+ EXPECT_EQ(r.readTimeoutSec, 20u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, LoweringTheGlobalTightensEveryProject) {
|
|
|
+ // Follows from min(), and is the reason a stored over-global value is kept
|
|
|
+ // rather than refused: it becomes meaningful again if the global drops.
|
|
|
+ Settings g;
|
|
|
+ g.embeddingConnectTimeoutSec = 10;
|
|
|
+ ProjectSettings p;
|
|
|
+ p.embeddingConnectTimeoutSec = 8;
|
|
|
+ const CollectionMeta none;
|
|
|
+ EXPECT_EQ(resolveEmbedding(g, &p, none).connectTimeoutSec, 8u);
|
|
|
+ g.embeddingConnectTimeoutSec = 3;
|
|
|
+ EXPECT_EQ(resolveEmbedding(g, &p, none).connectTimeoutSec, 3u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, AZeroOverrideIsUnsetRatherThanNoTimeout) {
|
|
|
+ // 0 means "no timeout" to the HTTP client, so reading a fat-fingered 0 as
|
|
|
+ // an override would produce precisely the unbounded call the budget split
|
|
|
+ // exists to prevent.
|
|
|
+ Settings g;
|
|
|
+ g.embeddingConnectTimeoutSec = 10;
|
|
|
+ g.embeddingReadTimeoutSec = 60;
|
|
|
+ ProjectSettings p;
|
|
|
+ p.embeddingConnectTimeoutSec = 0;
|
|
|
+ p.embeddingReadTimeoutSec = 0;
|
|
|
+ const CollectionMeta none;
|
|
|
+ const ResolvedEmbedding r = resolveEmbedding(g, &p, none);
|
|
|
+ EXPECT_EQ(r.connectTimeoutSec, 10u);
|
|
|
+ EXPECT_EQ(r.readTimeoutSec, 60u);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, ATimeoutOnlyProjectCountsAsAnEmbeddingOverride) {
|
|
|
+ // Otherwise DELETE /settings/embeddings would report nothing to revert
|
|
|
+ // while a timeout override was still in force, and the settings document
|
|
|
+ // could be dropped with it.
|
|
|
+ ProjectSettings p;
|
|
|
+ p.embeddingReadTimeoutSec = 4;
|
|
|
+ EXPECT_TRUE(p.hasEmbeddingOverrides());
|
|
|
+ EXPECT_TRUE(p.hasAnyOverrides());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(EmbeddingTimeouts, RoundTripThroughJson) {
|
|
|
+ ProjectSettings p;
|
|
|
+ EXPECT_FALSE(p.toJson().contains("embedding_connect_timeout_sec"));
|
|
|
+ p.embeddingConnectTimeoutSec = 2;
|
|
|
+ p.embeddingReadTimeoutSec = 4;
|
|
|
+ const ProjectSettings back = ProjectSettings::fromJson(p.toJson());
|
|
|
+ ASSERT_TRUE(back.embeddingConnectTimeoutSec.has_value());
|
|
|
+ ASSERT_TRUE(back.embeddingReadTimeoutSec.has_value());
|
|
|
+ EXPECT_EQ(*back.embeddingConnectTimeoutSec, 2u);
|
|
|
+ EXPECT_EQ(*back.embeddingReadTimeoutSec, 4u);
|
|
|
+}
|
|
|
+
|
|
|
// The per-project wall-time maximum. Resolved by a pure function for the same
|
|
|
// reason the function policy is: the precedence is the behaviour, and it should
|
|
|
// be assertable without a database, a runner or a clock.
|
|
|
|
|
|
TEST(MaxFunctionWallTime, AbsentMeansNoProjectCap) {
|
|
|
// 0, not "no time": the runner reads 0 as "the ceiling is the only cap".
|
|
|
- EXPECT_EQ(maxFunctionWallTimeMsFor(nullptr), 0);
|
|
|
+ using K = functions::RunKind;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(nullptr, K::Http), 0);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(nullptr, K::Job), 0);
|
|
|
const ProjectSettings p;
|
|
|
- EXPECT_EQ(maxFunctionWallTimeMsFor(&p), 0);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 0);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 0);
|
|
|
}
|
|
|
|
|
|
-TEST(MaxFunctionWallTime, UsesTheProjectValueWhenSet) {
|
|
|
+TEST(MaxFunctionWallTime, TheTwoKindsAreIndependent) {
|
|
|
+ // The whole point of splitting it: capping routes at 10 s must not cap
|
|
|
+ // cron work at 10 s. With one number the only safe setting was no cap.
|
|
|
+ using K = functions::RunKind;
|
|
|
ProjectSettings p;
|
|
|
- p.maxFunctionWallTimeMs = 30000;
|
|
|
- EXPECT_EQ(maxFunctionWallTimeMsFor(&p), 30000);
|
|
|
+ p.maxFunctionWallTimeHttpMs = 10000;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 10000);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 0) << "an HTTP cap must not cap jobs";
|
|
|
+
|
|
|
+ p = ProjectSettings{};
|
|
|
+ p.maxFunctionWallTimeJobMs = 60000;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 60000);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 0) << "a job cap must not cap routes";
|
|
|
}
|
|
|
|
|
|
TEST(MaxFunctionWallTime, ANonPositiveStoredValueIsTreatedAsUnset) {
|
|
|
// A fat-fingered 0 means "I did not mean to set one", not "no function in
|
|
|
// this project may ever run".
|
|
|
+ using K = functions::RunKind;
|
|
|
ProjectSettings p;
|
|
|
- p.maxFunctionWallTimeMs = 0;
|
|
|
- EXPECT_EQ(maxFunctionWallTimeMsFor(&p), 0);
|
|
|
- p.maxFunctionWallTimeMs = -1;
|
|
|
- EXPECT_EQ(maxFunctionWallTimeMsFor(&p), 0);
|
|
|
+ p.maxFunctionWallTimeHttpMs = 0;
|
|
|
+ p.maxFunctionWallTimeJobMs = -1;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 0);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 0);
|
|
|
}
|
|
|
|
|
|
TEST(MaxFunctionWallTime, RoundTripsAndIsNotWrittenWhenUnset) {
|
|
|
ProjectSettings p;
|
|
|
+ EXPECT_FALSE(p.toJson().contains("max_function_wall_time_http_ms"));
|
|
|
+ EXPECT_FALSE(p.toJson().contains("max_function_wall_time_job_ms"));
|
|
|
EXPECT_FALSE(p.toJson().contains("max_function_wall_time_ms"));
|
|
|
|
|
|
- p.maxFunctionWallTimeMs = 45000;
|
|
|
+ p.maxFunctionWallTimeHttpMs = 5000;
|
|
|
+ p.maxFunctionWallTimeJobMs = 45000;
|
|
|
const ProjectSettings back = ProjectSettings::fromJson(p.toJson());
|
|
|
- ASSERT_TRUE(back.maxFunctionWallTimeMs.has_value());
|
|
|
- EXPECT_EQ(*back.maxFunctionWallTimeMs, 45000);
|
|
|
+ ASSERT_TRUE(back.maxFunctionWallTimeHttpMs.has_value());
|
|
|
+ ASSERT_TRUE(back.maxFunctionWallTimeJobMs.has_value());
|
|
|
+ EXPECT_EQ(*back.maxFunctionWallTimeHttpMs, 5000);
|
|
|
+ EXPECT_EQ(*back.maxFunctionWallTimeJobMs, 45000);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(MaxFunctionWallTime, APreSplitDocumentSeedsBothKinds) {
|
|
|
+ // A document written before the split carries only the bare key and meant
|
|
|
+ // "both", so reading it must not silently drop the cap on either kind.
|
|
|
+ const ProjectSettings p =
|
|
|
+ ProjectSettings::fromJson({{"project", "p"}, {"max_function_wall_time_ms", 20000}});
|
|
|
+ using K = functions::RunKind;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 20000);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 20000);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(MaxFunctionWallTime, APerKindKeyWinsOverTheBareOne) {
|
|
|
+ // Both spellings present is what a newer server writes, deliberately, so
|
|
|
+ // an older one still sees a cap. The per-kind value is the real one.
|
|
|
+ const ProjectSettings p = ProjectSettings::fromJson({{"project", "p"},
|
|
|
+ {"max_function_wall_time_ms", 10000},
|
|
|
+ {"max_function_wall_time_job_ms", 60000}});
|
|
|
+ using K = functions::RunKind;
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Http), 10000);
|
|
|
+ EXPECT_EQ(maxFunctionWallTimeMsFor(&p, K::Job), 60000);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(MaxFunctionWallTime, TheCompatKeyCarriesTheTighterOfTheTwo) {
|
|
|
+ // Written so a ROLLBACK to a server that only understands the bare key
|
|
|
+ // still enforces something. The tighter value, because a rollback that
|
|
|
+ // loosens a limit an admin set is the failure worth avoiding.
|
|
|
+ ProjectSettings p;
|
|
|
+ p.maxFunctionWallTimeHttpMs = 10000;
|
|
|
+ p.maxFunctionWallTimeJobMs = 60000;
|
|
|
+ const nlohmann::json j = p.toJson();
|
|
|
+ ASSERT_TRUE(j.contains("max_function_wall_time_ms"));
|
|
|
+ EXPECT_EQ(j.at("max_function_wall_time_ms").get<int64_t>(), 10000);
|
|
|
+
|
|
|
+ // One kind only: the compat key carries it rather than being omitted,
|
|
|
+ // otherwise a rollback would see no cap at all.
|
|
|
+ ProjectSettings jobOnly;
|
|
|
+ jobOnly.maxFunctionWallTimeJobMs = 30000;
|
|
|
+ EXPECT_EQ(jobOnly.toJson().at("max_function_wall_time_ms").get<int64_t>(), 30000);
|
|
|
}
|
|
|
|
|
|
TEST(MaxFunctionWallTime, ABudgetOnlyProjectIsNotTreatedAsEmpty) {
|
|
|
// Otherwise clearing an embedding override would delete the settings
|
|
|
- // document and silently remove the project's cap with it.
|
|
|
- ProjectSettings p;
|
|
|
- p.maxFunctionWallTimeMs = 1000;
|
|
|
- EXPECT_TRUE(p.hasAnyOverrides());
|
|
|
- EXPECT_FALSE(p.hasEmbeddingOverrides());
|
|
|
+ // document and silently remove the project's cap with it. Checked for each
|
|
|
+ // kind separately - a project that caps only jobs is still not empty.
|
|
|
+ ProjectSettings http;
|
|
|
+ http.maxFunctionWallTimeHttpMs = 1000;
|
|
|
+ EXPECT_TRUE(http.hasAnyOverrides());
|
|
|
+ EXPECT_FALSE(http.hasEmbeddingOverrides());
|
|
|
+
|
|
|
+ ProjectSettings job;
|
|
|
+ job.maxFunctionWallTimeJobMs = 1000;
|
|
|
+ EXPECT_TRUE(job.hasAnyOverrides());
|
|
|
+ EXPECT_FALSE(job.hasEmbeddingOverrides());
|
|
|
}
|