api_huggingface 0.6.1

HuggingFace's API for accessing large language models (LLMs) and embeddings.
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
//! Integration tests for Dynamic Configuration
//!
//! These tests verify the dynamic configuration functionality.
//! Tests cover configuration updates, watchers, validation, history, and rollback.
//!
//! ## Test Coverage
//!
//! - Configuration updates
//! - Watcher notifications
//! - Concurrent updates
//! - Configuration validation
//! - History tracking
//! - Rollback functionality
//! - Integration with reliability components

#![ allow( clippy::field_reassign_with_default ) ]
#![ allow( clippy::map_unwrap_or ) ]
#![ allow( clippy::match_wild_err_arm ) ]
#![ allow( clippy::ignored_unit_patterns ) ]

use api_huggingface::config::{DynamicConfig, ReliabilityConfig};
use api_huggingface::reliability::{
  CircuitBreakerConfig,
  RateLimiterConfig,
  FailoverConfig,
  FailoverStrategy,
  HealthCheckConfig,
  HealthCheckStrategy,
};
use core::time::Duration;
use std::sync::Arc;
use tokio::sync::RwLock;

// ============================================================================
// Configuration Update Tests
// ============================================================================

#[ tokio::test ]
async fn test_update_circuit_breaker_config() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 5,
  success_threshold : 2,
  timeout : Duration::from_secs( 60 ),
  } );

  let result = dynamic_config.update( new_config ).await;
  assert!( result.is_ok( ), "Update should succeed" );

  let current = dynamic_config.get( ).await;
  assert!( current.circuit_breaker.is_some( ));
  assert_eq!( current.circuit_breaker.unwrap( ).failure_threshold, 5 );
}

#[ tokio::test ]
async fn test_update_rate_limiter_config() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.rate_limiter = Some( RateLimiterConfig {
  requests_per_second : Some( 10 ),
  requests_per_minute : Some( 500 ),
  requests_per_hour : Some( 10000 ),
  } );

  let result = dynamic_config.update( new_config ).await;
  assert!( result.is_ok( ), "Update should succeed" );

  let current = dynamic_config.get( ).await;
  assert!( current.rate_limiter.is_some( ));
  assert_eq!( current.rate_limiter.unwrap( ).requests_per_second, Some( 10 ));
}

#[ tokio::test ]
async fn test_update_failover_config() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.failover = Some( FailoverConfig {
  endpoints : vec!["endpoint1".to_string( ), "endpoint2".to_string( ) ],
  strategy : FailoverStrategy::Priority,
  max_retries : 3,
  failure_window : Duration::from_secs( 300 ),
  failure_threshold : 5,
  } );

  let result = dynamic_config.update( new_config ).await;
  assert!( result.is_ok( ), "Update should succeed" );

  let current = dynamic_config.get( ).await;
  assert!( current.failover.is_some( ));
  assert_eq!( current.failover.unwrap( ).endpoints.len( ), 2 );
}

#[ tokio::test ]
async fn test_update_health_check_config() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.health_check = Some( HealthCheckConfig {
  endpoint : "https://api.example.com".to_string( ),
  strategy : HealthCheckStrategy::LightweightApi,
  check_interval : Duration::from_secs( 30 ),
  timeout : Duration::from_secs( 5 ),
  unhealthy_threshold : 3,
  } );

  let result = dynamic_config.update( new_config ).await;
  assert!( result.is_ok( ), "Update should succeed" );

  let current = dynamic_config.get( ).await;
  assert!( current.health_check.is_some( ));
  assert_eq!( current.health_check.unwrap( ).endpoint, "https://api.example.com" );
}

#[ tokio::test ]
async fn test_update_all_configs_together() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 3,
  success_threshold : 2,
  timeout : Duration::from_secs( 30 ),
  } );
  new_config.rate_limiter = Some( RateLimiterConfig {
  requests_per_second : Some( 5 ),
  requests_per_minute : None,
  requests_per_hour : None,
  } );

  let result = dynamic_config.update( new_config ).await;
  assert!( result.is_ok( ));

  let current = dynamic_config.get( ).await;
  assert!( current.circuit_breaker.is_some( ));
  assert!( current.rate_limiter.is_some( ));
  assert!( current.failover.is_none( ));
  assert!( current.health_check.is_none( ));
}

// ============================================================================
// Watcher Tests
// ============================================================================

#[ tokio::test ]
async fn test_watcher_receives_notification() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let notified = Arc::new( RwLock::new( false ));
  let notified_clone = notified.clone( );

  dynamic_config.add_watcher( move |_old, _new| {
  let notified = notified_clone.clone( );
  tokio::spawn( async move {
      let mut n = notified.write( ).await;
      *n = true;
  } );
  } ).await;

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  // Give watcher time to execute
  tokio::time::sleep( Duration::from_millis( 50 )).await;

  assert!( *notified.read( ).await, "Watcher should be notified" );
}

#[ tokio::test ]
async fn test_multiple_watchers_all_notified() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let count = Arc::new( RwLock::new( 0 ));

  let count_clone1 = count.clone( );
  dynamic_config.add_watcher( move |_, _| {
  let count = count_clone1.clone( );
  tokio::spawn( async move {
      let mut c = count.write( ).await;
      *c += 1;
  } );
  } ).await;

  let count_clone2 = count.clone( );
  dynamic_config.add_watcher( move |_, _| {
  let count = count_clone2.clone( );
  tokio::spawn( async move {
      let mut c = count.write( ).await;
      *c += 1;
  } );
  } ).await;

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  // Give watchers time to execute
  tokio::time::sleep( Duration::from_millis( 100 )).await;

  assert_eq!( *count.read( ).await, 2, "Both watchers should be notified" );
}

#[ tokio::test ]
async fn test_watcher_receives_old_and_new_config() 
{
  let mut initial_config = ReliabilityConfig::default( );
  initial_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 3,
  success_threshold : 2,
  timeout : Duration::from_secs( 30 ),
  } );

  let dynamic_config = DynamicConfig::new( initial_config );

  let old_threshold = Arc::new( RwLock::new( 0 ));
  let new_threshold = Arc::new( RwLock::new( 0 ));

  let old_clone = old_threshold.clone( );
  let new_clone = new_threshold.clone( );

  dynamic_config.add_watcher( move |old, new| {
  let old_t = old_clone.clone( );
  let new_t = new_clone.clone( );
  let old_val = old.circuit_breaker.as_ref( ).map( |cb| cb.failure_threshold ).unwrap_or( 0 );
  let new_val = new.circuit_breaker.as_ref( ).map( |cb| cb.failure_threshold ).unwrap_or( 0 );

  tokio::spawn( async move {
      *old_t.write( ).await = old_val;
      *new_t.write( ).await = new_val;
  } );
  } ).await;

  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 10,
  success_threshold : 2,
  timeout : Duration::from_secs( 30 ),
  } );

  dynamic_config.update( new_config ).await.unwrap( );

  // Give watcher time to execute
  tokio::time::sleep( Duration::from_millis( 50 )).await;

  assert_eq!( *old_threshold.read( ).await, 3 );
  assert_eq!( *new_threshold.read( ).await, 10 );
}

#[ tokio::test ]
async fn test_clear_watchers() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  dynamic_config.add_watcher( |_, _| {} ).await;
  dynamic_config.add_watcher( |_, _| {} ).await;

  assert_eq!( dynamic_config.watcher_count( ).await, 2 );

  dynamic_config.clear_watchers( ).await;

  assert_eq!( dynamic_config.watcher_count( ).await, 0 );
}

// ============================================================================
// Validation Tests
// ============================================================================

#[ tokio::test ]
async fn test_validation_rejects_zero_circuit_breaker_thresholds() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  let mut invalid_config = ReliabilityConfig::default( );
  invalid_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 0,
  success_threshold : 2,
  timeout : Duration::from_secs( 60 ),
  } );

  let result = dynamic_config.update( invalid_config ).await;
  assert!( result.is_err( ), "Should reject zero failure threshold" );
}

#[ tokio::test ]
async fn test_validation_rejects_empty_rate_limiter() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  let mut invalid_config = ReliabilityConfig::default( );
  invalid_config.rate_limiter = Some( RateLimiterConfig {
  requests_per_second : None,
  requests_per_minute : None,
  requests_per_hour : None,
  } );

  let result = dynamic_config.update( invalid_config ).await;
  assert!( result.is_err( ), "Should reject rate limiter with no limits" );
}

#[ tokio::test ]
async fn test_validation_rejects_empty_failover_endpoints() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  let mut invalid_config = ReliabilityConfig::default( );
  invalid_config.failover = Some( FailoverConfig {
  endpoints : vec![ ],
  strategy : FailoverStrategy::Priority,
  max_retries : 3,
  failure_window : Duration::from_secs( 300 ),
  failure_threshold : 5,
  } );

  let result = dynamic_config.update( invalid_config ).await;
  assert!( result.is_err( ), "Should reject empty endpoints list" );
}

#[ tokio::test ]
async fn test_validation_rejects_empty_health_check_endpoint() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  let mut invalid_config = ReliabilityConfig::default( );
  invalid_config.health_check = Some( HealthCheckConfig {
  endpoint : String::new( ),
  strategy : HealthCheckStrategy::Ping,
  check_interval : Duration::from_secs( 30 ),
  timeout : Duration::from_secs( 5 ),
  unhealthy_threshold : 3,
  } );

  let result = dynamic_config.update( invalid_config ).await;
  assert!( result.is_err( ), "Should reject empty endpoint" );
}

#[ tokio::test ]
async fn test_is_valid_helper_function() 
{
  let valid_config = ReliabilityConfig::default( );
  assert!( DynamicConfig::is_valid( &valid_config ));

  let mut invalid_config = ReliabilityConfig::default( );
  invalid_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 0,
  success_threshold : 0,
  timeout : Duration::from_secs( 60 ),
  } );

  assert!( !DynamicConfig::is_valid( &invalid_config ));
}

// ============================================================================
// History Tests
// ============================================================================

#[ tokio::test ]
async fn test_history_tracks_updates() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  assert_eq!( dynamic_config.history_size( ).await, 0 );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  assert_eq!( dynamic_config.history_size( ).await, 1 );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  assert_eq!( dynamic_config.history_size( ).await, 2 );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  assert_eq!( dynamic_config.history_size( ).await, 3 );
}

#[ tokio::test ]
async fn test_history_respects_max_size() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::with_history_size( config, 3 );

  for _ in 0..10
  {
  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  }

  assert_eq!( dynamic_config.history_size( ).await, 3, "Should keep only last 3" );
}

#[ tokio::test ]
async fn test_get_history_returns_configs() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  let history = dynamic_config.get_history( ).await;
  assert_eq!( history.len( ), 2 );
}

#[ tokio::test ]
async fn test_clear_history() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  assert_eq!( dynamic_config.history_size( ).await, 2 );

  dynamic_config.clear_history( ).await;

  assert_eq!( dynamic_config.history_size( ).await, 0 );
}

// ============================================================================
// Rollback Tests
// ============================================================================

#[ tokio::test ]
async fn test_rollback_restores_previous_config() 
{
  let mut initial_config = ReliabilityConfig::default( );
  initial_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 3,
  success_threshold : 2,
  timeout : Duration::from_secs( 30 ),
  } );

  let dynamic_config = DynamicConfig::new( initial_config );

  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 10,
  success_threshold : 5,
  timeout : Duration::from_secs( 120 ),
  } );

  dynamic_config.update( new_config ).await.unwrap( );

  let current = dynamic_config.get( ).await;
  assert_eq!( current.circuit_breaker.as_ref( ).unwrap( ).failure_threshold, 10 );

  dynamic_config.rollback( ).await.unwrap( );

  let rolled_back = dynamic_config.get( ).await;
  assert_eq!( rolled_back.circuit_breaker.as_ref( ).unwrap( ).failure_threshold, 3 );
}

#[ tokio::test ]
async fn test_rollback_multiple_times() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  // Update 3 times with different thresholds
  for threshold in [5, 10, 15 ]
  {
  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
      failure_threshold : threshold,
      success_threshold : 2,
      timeout : Duration::from_secs( 60 ),
  } );
  dynamic_config.update( new_config ).await.unwrap( );
  }

  assert_eq!( dynamic_config.get( ).await.circuit_breaker.unwrap( ).failure_threshold, 15 );

  dynamic_config.rollback( ).await.unwrap( );
  assert_eq!( dynamic_config.get( ).await.circuit_breaker.unwrap( ).failure_threshold, 10 );

  dynamic_config.rollback( ).await.unwrap( );
  assert_eq!( dynamic_config.get( ).await.circuit_breaker.unwrap( ).failure_threshold, 5 );
}

#[ tokio::test ]
async fn test_rollback_fails_with_no_history() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( config );

  let result = dynamic_config.rollback( ).await;
  assert!( result.is_err( ), "Should fail with no history" );
}

#[ tokio::test ]
async fn test_rollback_notifies_watchers() 
{
  let mut initial_config = ReliabilityConfig::default( );
  initial_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 3,
  success_threshold : 2,
  timeout : Duration::from_secs( 30 ),
  } );

  let dynamic_config = DynamicConfig::new( initial_config );

  let notified = Arc::new( RwLock::new( false ));
  let notified_clone = notified.clone( );

  dynamic_config.add_watcher( move |_, _| {
  let n = notified_clone.clone( );
  tokio::spawn( async move {
      *n.write( ).await = true;
  } );
  } ).await;

  let mut new_config = ReliabilityConfig::default( );
  new_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 10,
  success_threshold : 5,
  timeout : Duration::from_secs( 120 ),
  } );

  dynamic_config.update( new_config ).await.unwrap( );

  // Reset notification flag
  *notified.write( ).await = false;

  dynamic_config.rollback( ).await.unwrap( );

  // Give watcher time to execute
  tokio::time::sleep( Duration::from_millis( 50 )).await;

  assert!( *notified.read( ).await, "Rollback should notify watchers" );
}

// ============================================================================
// Concurrent Access Tests
// ============================================================================

#[ tokio::test ]
async fn test_concurrent_updates() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = Arc::new( DynamicConfig::new( config ));

  let mut handles = vec![ ];

  for threshold in 1..=10
  {
  let dc = dynamic_config.clone( );
  let handle = tokio::spawn( async move {
      let mut config = ReliabilityConfig::default( );
      config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : threshold,
  success_threshold : 2,
  timeout : Duration::from_secs( 60 ),
      } );
      dc.update( config ).await
  } );
  handles.push( handle );
  }

  let mut successes = 0;
  for handle in handles
  {
  if let Ok( Ok( _ )) = handle.await
  {
      successes += 1;
  }
  }

  assert_eq!( successes, 10, "All concurrent updates should succeed" );
  assert_eq!( dynamic_config.history_size( ).await, 10 );
}

#[ tokio::test ]
async fn test_concurrent_reads_during_update() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = Arc::new( DynamicConfig::new( config ));

  let mut handles = vec![ ];

  // Spawn update task
  let dc_update = dynamic_config.clone( );
  handles.push( tokio::spawn( async move {
  for _ in 0..5
  {
      dc_update.update( ReliabilityConfig::default( )).await.unwrap( );
      tokio::time::sleep( Duration::from_millis( 10 )).await;
  }
  } ));

  // Spawn multiple read tasks
  for _ in 0..10
  {
  let dc_read = dynamic_config.clone( );
  handles.push( tokio::spawn( async move {
      for _ in 0..20
      {
  let _ = dc_read.get( ).await;
  tokio::time::sleep( Duration::from_millis( 5 )).await;
      }
  } ));
  }

  for handle in handles
  {
  handle.await.unwrap( );
  }

  // If we got here without deadlock, test passed
}

// ============================================================================
// Configuration Clone and Timestamp Tests
// ============================================================================

#[ tokio::test ]
async fn test_config_timestamp_updates_on_change() 
{
  let initial_config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::new( initial_config );

  let timestamp1 = dynamic_config.get( ).await.timestamp;

  tokio::time::sleep( Duration::from_millis( 10 )).await;

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  let timestamp2 = dynamic_config.get( ).await.timestamp;

  assert!( timestamp2 > timestamp1, "Timestamp should update on config change" );
}

#[ tokio::test ]
async fn test_config_clone() 
{
  let mut config1 = ReliabilityConfig::default( );
  config1.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 5,
  success_threshold : 2,
  timeout : Duration::from_secs( 60 ),
  } );

  let config2 = config1.clone( );

  assert!( config2.circuit_breaker.is_some( ));
  assert_eq!( config2.circuit_breaker.unwrap( ).failure_threshold, 5 );
}

// ============================================================================
// Edge Cases
// ============================================================================

#[ tokio::test ]
async fn test_update_with_none_values() 
{
  let mut initial_config = ReliabilityConfig::default( );
  initial_config.circuit_breaker = Some( CircuitBreakerConfig {
  failure_threshold : 5,
  success_threshold : 2,
  timeout : Duration::from_secs( 60 ),
  } );

  let dynamic_config = DynamicConfig::new( initial_config );

  // Update to config with all None
  let empty_config = ReliabilityConfig::default( );
  dynamic_config.update( empty_config ).await.unwrap( );

  let current = dynamic_config.get( ).await;
  assert!( current.circuit_breaker.is_none( ));
}

#[ tokio::test ]
async fn test_zero_history_size() 
{
  let config = ReliabilityConfig::default( );
  let dynamic_config = DynamicConfig::with_history_size( config, 0 );

  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );
  dynamic_config.update( ReliabilityConfig::default( )).await.unwrap( );

  assert_eq!( dynamic_config.history_size( ).await, 0, "Should not keep history" );

  let result = dynamic_config.rollback( ).await;
  assert!( result.is_err( ), "Cannot rollback with zero history" );
}