|
@@ -9,19 +9,38 @@ TEST(Config, DefaultsWhenEmpty) {
|
|
|
EXPECT_EQ(c.httpBind, "0.0.0.0");
|
|
EXPECT_EQ(c.httpBind, "0.0.0.0");
|
|
|
EXPECT_EQ(c.httpPort, 8080);
|
|
EXPECT_EQ(c.httpPort, 8080);
|
|
|
EXPECT_EQ(c.dbAddress, "localhost:9004");
|
|
EXPECT_EQ(c.dbAddress, "localhost:9004");
|
|
|
|
|
+ // The per-call gRPC deadline. 5000 is the value DbGateway hardcoded as a
|
|
|
|
|
+ // default argument before this was configurable, and the default is pinned
|
|
|
|
|
+ // here BECAUSE it must not drift: moving it silently changes whether a
|
|
|
|
|
+ // slow database call reaches a caller as a 503 or as a late 200, which is
|
|
|
|
|
+ // a decision for whoever sets it rather than for a release.
|
|
|
|
|
+ EXPECT_EQ(c.dbTimeoutMs, 5000u);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(Config, ParsesProvidedValues) {
|
|
TEST(Config, ParsesProvidedValues) {
|
|
|
auto j = nlohmann::json::parse(R"({
|
|
auto j = nlohmann::json::parse(R"({
|
|
|
"log_level":"debug",
|
|
"log_level":"debug",
|
|
|
"http":{"bind_address":"127.0.0.1","port":9090},
|
|
"http":{"bind_address":"127.0.0.1","port":9090},
|
|
|
- "database":{"address":"db:9004"}
|
|
|
|
|
|
|
+ "database":{"address":"db:9004","timeout_ms":20000}
|
|
|
})");
|
|
})");
|
|
|
Config c = Config::fromJson(j);
|
|
Config c = Config::fromJson(j);
|
|
|
EXPECT_EQ(c.logLevel, "debug");
|
|
EXPECT_EQ(c.logLevel, "debug");
|
|
|
EXPECT_EQ(c.httpBind, "127.0.0.1");
|
|
EXPECT_EQ(c.httpBind, "127.0.0.1");
|
|
|
EXPECT_EQ(c.httpPort, 9090);
|
|
EXPECT_EQ(c.httpPort, 9090);
|
|
|
EXPECT_EQ(c.dbAddress, "db:9004");
|
|
EXPECT_EQ(c.dbAddress, "db:9004");
|
|
|
|
|
+ EXPECT_EQ(c.dbTimeoutMs, 20000u);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// The pairing that makes the test above mean something: a `database` block
|
|
|
|
|
+// that names only the address must leave the deadline alone. Without this, a
|
|
|
|
|
+// parser that overwrote the timeout with a zero whenever the section was
|
|
|
|
|
+// present would still pass - and a zero is "no timeout" to the client, which
|
|
|
|
|
+// is the unbounded call the deadline exists to prevent.
|
|
|
|
|
+TEST(Config, ADatabaseBlockWithoutATimeoutKeepsTheDefault) {
|
|
|
|
|
+ auto j = nlohmann::json::parse(R"({"database":{"address":"other:9004"}})");
|
|
|
|
|
+ Config c = Config::fromJson(j);
|
|
|
|
|
+ EXPECT_EQ(c.dbAddress, "other:9004");
|
|
|
|
|
+ EXPECT_EQ(c.dbTimeoutMs, 5000u);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TEST(Config, IgnoresUnknownKeys) {
|
|
TEST(Config, IgnoresUnknownKeys) {
|