feat(rpc): implement health check service and error handling
- Added `RpcError` enum for comprehensive error handling in RPC operations. - Introduced `HealthReporter` and `HealthService` for managing service health statuses. - Implemented health check and watch functionality in the health service. - Created integration tests for health check service, covering various scenarios. - Added unit tests for client options validation and stream functionality. - Established logging infrastructure for terminal and registry components. - Implemented logging lifecycle management and conflict resolution in tests.
This commit is contained in:
@@ -10,14 +10,24 @@ fn defaults_file_and_environment_precedence() {
|
||||
let config = Config::from_file(&path, HashMap::new()).unwrap();
|
||||
assert_eq!(config.port, 50051);
|
||||
assert_eq!(config.health_interval, Duration::from_secs(10));
|
||||
std::fs::write(&path, "REGISTRY_PORT=1234\nREGISTRY_HOST=localhost\n").unwrap();
|
||||
assert_eq!(config.log_level, "info");
|
||||
assert_eq!(config.log_dir, std::path::Path::new("logs/registry"));
|
||||
assert_eq!(config.log_max_files, 10);
|
||||
std::fs::write(&path, "PORT=1234\nHOST=localhost\nLOG_LEVEL=warn\nLOG_DIR=custom-logs\nLOG_MAX_FILES=4\nDATA_FILE_COUNT=7\n").unwrap();
|
||||
let config = Config::from_file(
|
||||
&path,
|
||||
HashMap::from([("REGISTRY_PORT".into(), "4321".into())]),
|
||||
HashMap::from([
|
||||
("PORT".into(), "4321".into()),
|
||||
("LOG_LEVEL".into(), "DEBUG".into()),
|
||||
]),
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(config.port, 4321);
|
||||
assert_eq!(config.host, "localhost");
|
||||
assert_eq!(config.log_level, "DEBUG");
|
||||
assert_eq!(config.log_dir, std::path::Path::new("custom-logs"));
|
||||
assert_eq!(config.log_max_files, 4);
|
||||
assert_eq!(config.data_file_count, 7);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -25,15 +35,24 @@ fn invalid_configuration_fails() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let path = directory.path().join(".env");
|
||||
for (key, value) in [
|
||||
("REGISTRY_PORT", "0"),
|
||||
("REGISTRY_PORT", "65536"),
|
||||
("REGISTRY_HEALTH_INTERVAL_SECS", "0"),
|
||||
("REGISTRY_HEALTH_TIMEOUT_SECS", "abc"),
|
||||
("REGISTRY_HOST", " "),
|
||||
("REGISTRY_DATA_PATH", ""),
|
||||
("PORT", "0"),
|
||||
("PORT", "65536"),
|
||||
("HEALTH_INTERVAL_SECS", "0"),
|
||||
("HEALTH_TIMEOUT_SECS", "abc"),
|
||||
("HOST", " "),
|
||||
("DATA_PATH", ""),
|
||||
("LOG_LEVEL", ""),
|
||||
("LOG_LEVEL", "verbose"),
|
||||
("LOG_DIR", " "),
|
||||
("LOG_MAX_FILES", "0"),
|
||||
("LOG_MAX_FILES", "-1"),
|
||||
("LOG_MAX_FILES", "18446744073709551616"),
|
||||
] {
|
||||
assert!(Config::from_file(&path, HashMap::from([(key.into(), value.into())])).is_err());
|
||||
}
|
||||
std::fs::write(&path, "REGISTRY_PORT='unterminated").unwrap();
|
||||
let config =
|
||||
Config::from_file(&path, HashMap::from([("LOG_LEVEL".into(), "off".into())])).unwrap();
|
||||
assert_eq!(config.log_level, "off");
|
||||
std::fs::write(&path, "PORT='unterminated").unwrap();
|
||||
assert!(Config::from_file(&path, HashMap::new()).is_err());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user