Create test-aware db env vars.
[rapid-gossip-sync-server] / src / config.rs
index b905c53f3b877f27b12e21d8fd816f9864a6a1a0..0655aa7d48f9013f2d6171d06e4c83eeb1d99bfa 100644 (file)
@@ -23,6 +23,10 @@ pub(crate) const MAX_SNAPSHOT_SCOPE: u32 = 3600 * 24 * 21; // three weeks
 /// That reminder may be either in the form of a channel announcement, or in the form of empty
 /// updates in both directions.
 pub(crate) const CHANNEL_REMINDER_AGE: Duration = Duration::from_secs(6 * 24 * 60 * 60);
+/// The number of successful peer connections to await prior to continuing to gossip storage.
+/// The application will still work if the number of specified peers is lower, as long as there is
+/// at least one successful peer connection, but it may result in long startup times.
+pub(crate) const CONNECTED_PEER_ASSERTION_LIMIT: usize = 5;
 pub(crate) const DOWNLOAD_NEW_GOSSIP: bool = true;
 
 pub(crate) fn snapshot_generation_interval() -> u32 {
@@ -70,13 +74,19 @@ pub(crate) fn cache_path() -> String {
 
 pub(crate) fn db_connection_config() -> Config {
        let mut config = Config::new();
-       let host = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_HOST").unwrap_or("localhost".to_string());
-       let user = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_USER").unwrap_or("alice".to_string());
-       let db = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_NAME").unwrap_or("ln_graph_sync".to_string());
+       let env_name_prefix = if cfg!(test) {
+               "RAPID_GOSSIP_TEST_DB"
+       } else {
+               "RAPID_GOSSIP_SYNC_SERVER_DB"
+       };
+
+       let host = env::var(format!("{}{}", env_name_prefix, "_HOST")).unwrap_or("localhost".to_string());
+       let user = env::var(format!("{}{}", env_name_prefix, "_USER")).unwrap_or("alice".to_string());
+       let db = env::var(format!("{}{}", env_name_prefix, "_NAME")).unwrap_or("ln_graph_sync".to_string());
        config.host(&host);
        config.user(&user);
        config.dbname(&db);
-       if let Ok(password) = env::var("RAPID_GOSSIP_SYNC_SERVER_DB_PASSWORD") {
+       if let Ok(password) = env::var(format!("{}{}", env_name_prefix, "_PASSWORD")) {
                config.password(&password);
        }
        config