things3-core 2.1.0

Core library for Things 3 database access and data models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
//! Configuration Hot Reloading
//!
//! This module provides functionality for hot-reloading configuration files
//! without restarting the server.

use crate::error::{Result, ThingsError};
use crate::mcp_config::McpServerConfig;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::{broadcast, RwLock};
use tokio::time::interval;
use tracing::{debug, error, info};

/// Configuration hot reloader
#[derive(Debug)]
pub struct ConfigHotReloader {
    /// Current configuration
    config: Arc<RwLock<McpServerConfig>>,
    /// Configuration file path
    config_path: PathBuf,
    /// Reload interval
    reload_interval: Duration,
    /// Whether hot reloading is enabled
    enabled: bool,
    /// Broadcast channel for configuration change notifications
    change_tx: broadcast::Sender<McpServerConfig>,
    /// Last modification time of the config file
    last_modified: Option<std::time::SystemTime>,
}

impl ConfigHotReloader {
    /// Create a new configuration hot reloader
    ///
    /// # Arguments
    /// * `config` - Initial configuration
    /// * `config_path` - Path to the configuration file to watch
    /// * `reload_interval` - How often to check for changes
    ///
    /// # Errors
    /// Returns an error if the configuration file cannot be accessed
    pub fn new(
        config: McpServerConfig,
        config_path: PathBuf,
        reload_interval: Duration,
    ) -> Result<Self> {
        // Validate that the config file exists and is readable
        if !config_path.exists() {
            return Err(ThingsError::configuration(format!(
                "Configuration file does not exist: {}",
                config_path.display()
            )));
        }

        let (change_tx, _) = broadcast::channel(16);
        let last_modified = Self::get_file_modified_time(&config_path)?;

        Ok(Self {
            config: Arc::new(RwLock::new(config)),
            config_path,
            reload_interval,
            enabled: true,
            change_tx,
            last_modified: Some(last_modified),
        })
    }

    /// Create a hot reloader with default settings
    ///
    /// # Arguments
    /// * `config_path` - Path to the configuration file to watch
    ///
    /// # Errors
    /// Returns an error if the configuration file cannot be accessed
    pub fn with_default_settings(config_path: PathBuf) -> Result<Self> {
        let config = McpServerConfig::default();
        Self::new(config, config_path, Duration::from_secs(5))
    }

    /// Get the current configuration
    #[must_use]
    pub async fn get_config(&self) -> McpServerConfig {
        self.config.read().await.clone()
    }

    /// Update the configuration
    ///
    /// # Arguments
    /// * `new_config` - New configuration to set
    ///
    /// # Errors
    /// Returns an error if the configuration is invalid
    pub async fn update_config(&self, new_config: McpServerConfig) -> Result<()> {
        new_config.validate()?;

        let mut config = self.config.write().await;
        *config = new_config.clone();

        // Broadcast the change
        let _ = self.change_tx.send(new_config);

        info!("Configuration updated successfully");
        Ok(())
    }

    /// Get a receiver for configuration change notifications
    #[must_use]
    pub fn subscribe_to_changes(&self) -> broadcast::Receiver<McpServerConfig> {
        self.change_tx.subscribe()
    }

    /// Enable or disable hot reloading
    pub fn set_enabled(&mut self, enabled: bool) {
        self.enabled = enabled;
        if enabled {
            info!("Configuration hot reloading enabled");
        } else {
            info!("Configuration hot reloading disabled");
        }
    }

    /// Check if hot reloading is enabled
    #[must_use]
    pub fn is_enabled(&self) -> bool {
        self.enabled
    }

    /// Start the hot reloader task
    ///
    /// This will spawn a background task that periodically checks for configuration changes
    /// and reloads the configuration if changes are detected.
    ///
    /// # Errors
    /// Returns an error if the configuration cannot be loaded or if there are issues
    /// with the file system operations.
    pub fn start(&self) -> Result<()> {
        if !self.enabled {
            debug!("Hot reloading is disabled, not starting reloader task");
            return Ok(());
        }

        let config = Arc::clone(&self.config);
        let config_path = self.config_path.clone();
        let change_tx = self.change_tx.clone();
        let mut interval = interval(self.reload_interval);
        let mut last_modified = self.last_modified;

        info!(
            "Starting configuration hot reloader for: {}",
            config_path.display()
        );

        tokio::spawn(async move {
            loop {
                interval.tick().await;

                match Self::check_and_reload_config(
                    &config_path,
                    &config,
                    &change_tx,
                    &mut last_modified,
                )
                .await
                {
                    Ok(reloaded) => {
                        if reloaded {
                            debug!(
                                "Configuration reloaded from file: {}",
                                config_path.display()
                            );
                        }
                    }
                    Err(e) => {
                        error!("Failed to check/reload configuration: {}", e);
                    }
                }
            }
        });

        Ok(())
    }

    /// Check for configuration changes and reload if necessary
    async fn check_and_reload_config(
        config_path: &PathBuf,
        config: &Arc<RwLock<McpServerConfig>>,
        change_tx: &broadcast::Sender<McpServerConfig>,
        last_modified: &mut Option<std::time::SystemTime>,
    ) -> Result<bool> {
        // Check if the file has been modified
        let current_modified = Self::get_file_modified_time(config_path)?;

        if let Some(last) = *last_modified {
            if current_modified <= last {
                return Ok(false); // No changes
            }
        }

        // File has been modified, try to reload
        debug!("Configuration file modified, attempting to reload");

        match McpServerConfig::from_file(config_path) {
            Ok(new_config) => {
                // Validate the new configuration
                new_config.validate()?;

                // Update the configuration
                {
                    let mut current_config = config.write().await;
                    *current_config = new_config.clone();
                }

                // Broadcast the change
                let _ = change_tx.send(new_config);

                // Update the last modified time
                *last_modified = Some(current_modified);

                info!(
                    "Configuration successfully reloaded from: {}",
                    config_path.display()
                );
                Ok(true)
            }
            Err(e) => {
                error!(
                    "Failed to reload configuration from {}: {}",
                    config_path.display(),
                    e
                );
                Err(e)
            }
        }
    }

    /// Get the last modification time of a file
    fn get_file_modified_time(path: &PathBuf) -> Result<std::time::SystemTime> {
        let metadata = std::fs::metadata(path).map_err(|e| {
            ThingsError::Io(std::io::Error::other(format!(
                "Failed to get file metadata for {}: {}",
                path.display(),
                e
            )))
        })?;

        metadata.modified().map_err(|e| {
            ThingsError::Io(std::io::Error::other(format!(
                "Failed to get modification time for {}: {}",
                path.display(),
                e
            )))
        })
    }

    /// Manually trigger a configuration reload
    ///
    /// # Errors
    /// Returns an error if the configuration cannot be reloaded
    pub async fn reload_now(&self) -> Result<bool> {
        let mut last_modified = self.last_modified;
        Self::check_and_reload_config(
            &self.config_path,
            &self.config,
            &self.change_tx,
            &mut last_modified,
        )
        .await
    }

    /// Get the configuration file path being watched
    #[must_use]
    pub fn config_path(&self) -> &PathBuf {
        &self.config_path
    }

    /// Get the reload interval
    #[must_use]
    pub fn reload_interval(&self) -> Duration {
        self.reload_interval
    }

    /// Set the reload interval
    pub fn set_reload_interval(&mut self, interval: Duration) {
        self.reload_interval = interval;
        debug!("Configuration reload interval set to: {:?}", interval);
    }
}

/// Configuration change handler trait
#[async_trait::async_trait]
pub trait ConfigChangeHandler: Send + Sync {
    /// Handle a configuration change
    ///
    /// # Arguments
    /// * `old_config` - The previous configuration
    /// * `new_config` - The new configuration
    async fn handle_config_change(
        &self,
        old_config: &McpServerConfig,
        new_config: &McpServerConfig,
    );
}

/// Default configuration change handler that logs changes
pub struct DefaultConfigChangeHandler;

#[async_trait::async_trait]
impl ConfigChangeHandler for DefaultConfigChangeHandler {
    async fn handle_config_change(
        &self,
        old_config: &McpServerConfig,
        new_config: &McpServerConfig,
    ) {
        info!("Configuration changed:");

        if old_config.server.name != new_config.server.name {
            info!(
                "  Server name: {} -> {}",
                old_config.server.name, new_config.server.name
            );
        }
        if old_config.logging.level != new_config.logging.level {
            info!(
                "  Log level: {} -> {}",
                old_config.logging.level, new_config.logging.level
            );
        }
        if old_config.cache.enabled != new_config.cache.enabled {
            info!(
                "  Cache enabled: {} -> {}",
                old_config.cache.enabled, new_config.cache.enabled
            );
        }
        if old_config.performance.enabled != new_config.performance.enabled {
            info!(
                "  Performance monitoring: {} -> {}",
                old_config.performance.enabled, new_config.performance.enabled
            );
        }
        if old_config.security.authentication.enabled != new_config.security.authentication.enabled
        {
            info!(
                "  Authentication: {} -> {}",
                old_config.security.authentication.enabled,
                new_config.security.authentication.enabled
            );
        }
    }
}

/// Configuration hot reloader with change handler
pub struct ConfigHotReloaderWithHandler {
    /// The base hot reloader
    reloader: ConfigHotReloader,
    /// Change handler
    handler: Arc<dyn ConfigChangeHandler>,
}

impl ConfigHotReloaderWithHandler {
    /// Create a new hot reloader with a change handler
    ///
    /// # Arguments
    /// * `config` - Initial configuration
    /// * `config_path` - Path to the configuration file to watch
    /// * `reload_interval` - How often to check for changes
    /// * `handler` - Handler for configuration changes
    ///
    /// # Errors
    /// Returns an error if the configuration file cannot be accessed
    pub fn new(
        config: McpServerConfig,
        config_path: PathBuf,
        reload_interval: Duration,
        handler: Arc<dyn ConfigChangeHandler>,
    ) -> Result<Self> {
        let reloader = ConfigHotReloader::new(config, config_path, reload_interval)?;

        Ok(Self { reloader, handler })
    }

    /// Start the hot reloader with change handling
    ///
    /// # Errors
    /// Returns an error if the hot reloader cannot be started
    pub fn start_with_handler(&self) -> Result<()> {
        // Start the base reloader
        self.reloader.start()?;

        // Start the change handler task
        let mut change_rx = self.reloader.subscribe_to_changes();
        let handler = Arc::clone(&self.handler);
        let config = Arc::clone(&self.reloader.config);

        tokio::spawn(async move {
            let mut old_config = config.read().await.clone();

            while let Ok(new_config) = change_rx.recv().await {
                handler.handle_config_change(&old_config, &new_config).await;
                old_config = new_config;
            }
        });

        Ok(())
    }

    /// Get the underlying hot reloader
    #[must_use]
    pub fn reloader(&self) -> &ConfigHotReloader {
        &self.reloader
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::time::Duration;
    use tempfile::NamedTempFile;

    #[tokio::test]
    async fn test_config_hot_reloader_creation() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();
        assert!(reloader.is_enabled());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_with_default_settings() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::with_default_settings(config_path).unwrap();
        assert!(reloader.is_enabled());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_enable_disable() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let mut reloader =
            ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();
        assert!(reloader.is_enabled());

        reloader.set_enabled(false);
        assert!(!reloader.is_enabled());

        reloader.set_enabled(true);
        assert!(reloader.is_enabled());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_get_config() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let mut config = McpServerConfig::default();
        config.server.name = "test-server".to_string();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();
        let loaded_config = reloader.get_config().await;
        assert_eq!(loaded_config.server.name, "test-server");
    }

    #[tokio::test]
    async fn test_config_hot_reloader_update_config() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();

        let mut new_config = McpServerConfig::default();
        new_config.server.name = "updated-server".to_string();

        reloader.update_config(new_config).await.unwrap();

        let loaded_config = reloader.get_config().await;
        assert_eq!(loaded_config.server.name, "updated-server");
    }

    #[tokio::test]
    async fn test_config_hot_reloader_subscribe_to_changes() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();
        let mut change_rx = reloader.subscribe_to_changes();

        let mut new_config = McpServerConfig::default();
        new_config.server.name = "changed-server".to_string();

        reloader.update_config(new_config).await.unwrap();

        let received_config = change_rx.recv().await.unwrap();
        assert_eq!(received_config.server.name, "changed-server");
    }

    #[tokio::test]
    async fn test_config_hot_reloader_with_handler() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let handler = Arc::new(DefaultConfigChangeHandler);
        let reloader =
            ConfigHotReloaderWithHandler::new(config, config_path, Duration::from_secs(1), handler)
                .unwrap();

        assert!(reloader.reloader().is_enabled());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_nonexistent_file() {
        let config_path = PathBuf::from("/nonexistent/config.json");
        let config = McpServerConfig::default();

        let result = ConfigHotReloader::new(config, config_path, Duration::from_secs(1));
        assert!(result.is_err());
        let error = result.unwrap_err();
        assert!(matches!(error, ThingsError::Configuration { .. }));
    }

    #[tokio::test]
    async fn test_config_hot_reloader_invalid_config_file() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        // Write invalid JSON directly
        std::fs::write(&config_path, "{ invalid json }").unwrap();

        // Test that McpServerConfig::from_file fails with invalid JSON
        let result = McpServerConfig::from_file(&config_path);
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_file_permission_error() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        // Create reloader first
        let reloader =
            ConfigHotReloader::new(config, config_path.clone(), Duration::from_secs(1)).unwrap();

        // Remove the file to simulate permission error
        std::fs::remove_file(&config_path).unwrap();

        // Try to reload - should handle the error gracefully
        let result = reloader.reload_now().await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_concurrent_updates() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader =
            ConfigHotReloader::new(config, config_path.clone(), Duration::from_secs(1)).unwrap();
        let mut change_rx = reloader.subscribe_to_changes();

        // Update config multiple times concurrently
        let mut config1 = McpServerConfig::default();
        config1.server.name = "config1".to_string();

        let mut config2 = McpServerConfig::default();
        config2.server.name = "config2".to_string();

        // Update configs concurrently
        let reloader_clone = Arc::new(reloader);
        let reloader1 = Arc::clone(&reloader_clone);
        let reloader2 = Arc::clone(&reloader_clone);

        let handle1 = tokio::spawn(async move { reloader1.update_config(config1).await });

        let handle2 = tokio::spawn(async move { reloader2.update_config(config2).await });

        // Wait for both updates
        let _ = handle1.await.unwrap();
        let _ = handle2.await.unwrap();

        // Should receive at least one change notification
        let _received_config = change_rx.recv().await.unwrap();
    }

    #[tokio::test]
    async fn test_config_hot_reloader_validation_error() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader = ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();

        // Create an invalid config (empty server name should fail validation)
        let mut invalid_config = McpServerConfig::default();
        invalid_config.server.name = String::new(); // This should fail validation

        let result = reloader.update_config(invalid_config).await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_disabled_start() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let mut reloader =
            ConfigHotReloader::new(config, config_path, Duration::from_secs(1)).unwrap();
        reloader.set_enabled(false);

        // Start should succeed even when disabled
        let result = reloader.start();
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_reload_interval() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let mut reloader =
            ConfigHotReloader::new(config, config_path, Duration::from_secs(5)).unwrap();

        assert_eq!(reloader.reload_interval(), Duration::from_secs(5));

        reloader.set_reload_interval(Duration::from_secs(10));
        assert_eq!(reloader.reload_interval(), Duration::from_secs(10));
    }

    #[tokio::test]
    async fn test_config_hot_reloader_metadata_error() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader =
            ConfigHotReloader::new(config, config_path.clone(), Duration::from_secs(1)).unwrap();

        // Remove the file to cause metadata error
        std::fs::remove_file(&config_path).unwrap();

        // This should handle the error gracefully
        let result = reloader.reload_now().await;
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_with_handler_start() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let handler = Arc::new(DefaultConfigChangeHandler);
        let reloader =
            ConfigHotReloaderWithHandler::new(config, config_path, Duration::from_secs(1), handler)
                .unwrap();

        // Start with handler should succeed
        let result = reloader.start_with_handler();
        assert!(result.is_ok());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_file_modified_time() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        // Test getting file modified time
        let modified_time = ConfigHotReloader::get_file_modified_time(&config_path);
        assert!(modified_time.is_ok());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_file_modified_time_nonexistent() {
        let config_path = PathBuf::from("/nonexistent/file.json");

        // Test getting file modified time for nonexistent file
        let result = ConfigHotReloader::get_file_modified_time(&config_path);
        assert!(result.is_err());
    }

    #[tokio::test]
    async fn test_config_hot_reloader_config_path() {
        let temp_file = NamedTempFile::new().unwrap();
        let config_path = temp_file.path().with_extension("json");

        let config = McpServerConfig::default();
        config.to_file(&config_path, "json").unwrap();

        let reloader =
            ConfigHotReloader::new(config, config_path.clone(), Duration::from_secs(1)).unwrap();

        assert_eq!(reloader.config_path(), &config_path);
    }
}