@@ -18,7 +18,7 @@ use std::sync::{Arc, Mutex};
18
18
19
19
use async_trait:: async_trait;
20
20
use bytes:: Bytes ;
21
- use nativelink_config:: stores:: { FastSlowSpec , MemorySpec , NoopSpec , StoreSpec } ;
21
+ use nativelink_config:: stores:: { FastSlowSpec , MemorySpec , NoopSpec , StoreDirection , StoreSpec } ;
22
22
use nativelink_error:: { make_err, Code , Error , ResultExt } ;
23
23
use nativelink_macro:: nativelink_test;
24
24
use nativelink_metric:: MetricsComponent ;
@@ -35,20 +35,29 @@ use rand::{Rng, SeedableRng};
35
35
36
36
const MEGABYTE_SZ : usize = 1024 * 1024 ;
37
37
38
- fn make_stores ( ) -> ( Store , Store , Store ) {
38
+ fn make_stores_direction (
39
+ fast_direction : StoreDirection ,
40
+ slow_direction : StoreDirection ,
41
+ ) -> ( Store , Store , Store ) {
39
42
let fast_store = Store :: new ( MemoryStore :: new ( & MemorySpec :: default ( ) ) ) ;
40
43
let slow_store = Store :: new ( MemoryStore :: new ( & MemorySpec :: default ( ) ) ) ;
41
44
let fast_slow_store = Store :: new ( FastSlowStore :: new (
42
45
& FastSlowSpec {
43
46
fast : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
47
+ fast_direction,
44
48
slow : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
49
+ slow_direction,
45
50
} ,
46
51
fast_store. clone ( ) ,
47
52
slow_store. clone ( ) ,
48
53
) ) ;
49
54
( fast_slow_store, fast_store, slow_store)
50
55
}
51
56
57
+ fn make_stores ( ) -> ( Store , Store , Store ) {
58
+ make_stores_direction ( StoreDirection :: default ( ) , StoreDirection :: default ( ) )
59
+ }
60
+
52
61
fn make_random_data ( sz : usize ) -> Vec < u8 > {
53
62
let mut value = vec ! [ 0u8 ; sz] ;
54
63
let mut rng = SmallRng :: seed_from_u64 ( 1 ) ;
@@ -331,7 +340,9 @@ async fn drop_on_eof_completes_store_futures() -> Result<(), Error> {
331
340
let fast_slow_store = FastSlowStore :: new (
332
341
& FastSlowSpec {
333
342
fast : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
343
+ fast_direction : StoreDirection :: default ( ) ,
334
344
slow : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
345
+ slow_direction : StoreDirection :: default ( ) ,
335
346
} ,
336
347
fast_store,
337
348
slow_store,
@@ -372,7 +383,9 @@ async fn ignore_value_in_fast_store() -> Result<(), Error> {
372
383
let fast_slow_store = Arc :: new ( FastSlowStore :: new (
373
384
& FastSlowSpec {
374
385
fast : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
386
+ fast_direction : StoreDirection :: default ( ) ,
375
387
slow : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
388
+ slow_direction : StoreDirection :: default ( ) ,
376
389
} ,
377
390
fast_store. clone ( ) ,
378
391
slow_store,
@@ -395,7 +408,9 @@ async fn has_checks_fast_store_when_noop() -> Result<(), Error> {
395
408
let slow_store = Store :: new ( NoopStore :: new ( ) ) ;
396
409
let fast_slow_store_config = FastSlowSpec {
397
410
fast : StoreSpec :: memory ( MemorySpec :: default ( ) ) ,
411
+ fast_direction : StoreDirection :: default ( ) ,
398
412
slow : StoreSpec :: noop ( NoopSpec :: default ( ) ) ,
413
+ slow_direction : StoreDirection :: default ( ) ,
399
414
} ;
400
415
let fast_slow_store = Arc :: new ( FastSlowStore :: new (
401
416
& fast_slow_store_config,
@@ -430,3 +445,95 @@ async fn has_checks_fast_store_when_noop() -> Result<(), Error> {
430
445
) ;
431
446
Ok ( ( ) )
432
447
}
448
+
449
+ #[ nativelink_test]
450
+ async fn fast_get_only_not_updated ( ) -> Result < ( ) , Error > {
451
+ let ( fast_slow_store, fast_store, slow_store) =
452
+ make_stores_direction ( StoreDirection :: Get , StoreDirection :: Both ) ;
453
+ let digest = DigestInfo :: try_new ( VALID_HASH , 100 ) . unwrap ( ) ;
454
+ fast_slow_store
455
+ . update_oneshot ( digest, make_random_data ( 100 ) . into ( ) )
456
+ . await ?;
457
+ assert ! (
458
+ fast_store. has( digest) . await ?. is_none( ) ,
459
+ "Expected data to not be in the fast store"
460
+ ) ;
461
+ assert ! (
462
+ slow_store. has( digest) . await ?. is_some( ) ,
463
+ "Expected data in the slow store"
464
+ ) ;
465
+ Ok ( ( ) )
466
+ }
467
+
468
+ #[ nativelink_test]
469
+ async fn fast_readonly_only_not_updated ( ) -> Result < ( ) , Error > {
470
+ let ( fast_slow_store, fast_store, slow_store) =
471
+ make_stores_direction ( StoreDirection :: ReadOnly , StoreDirection :: Both ) ;
472
+ let digest = DigestInfo :: try_new ( VALID_HASH , 100 ) . unwrap ( ) ;
473
+ fast_slow_store
474
+ . update_oneshot ( digest, make_random_data ( 100 ) . into ( ) )
475
+ . await ?;
476
+ assert ! (
477
+ fast_store. has( digest) . await ?. is_none( ) ,
478
+ "Expected data to not be in the fast store"
479
+ ) ;
480
+ assert ! (
481
+ slow_store. has( digest) . await ?. is_some( ) ,
482
+ "Expected data in the slow store"
483
+ ) ;
484
+ Ok ( ( ) )
485
+ }
486
+
487
+ #[ nativelink_test]
488
+ async fn slow_readonly_only_not_updated ( ) -> Result < ( ) , Error > {
489
+ let ( fast_slow_store, fast_store, slow_store) =
490
+ make_stores_direction ( StoreDirection :: Both , StoreDirection :: ReadOnly ) ;
491
+ let digest = DigestInfo :: try_new ( VALID_HASH , 100 ) . unwrap ( ) ;
492
+ fast_slow_store
493
+ . update_oneshot ( digest, make_random_data ( 100 ) . into ( ) )
494
+ . await ?;
495
+ assert ! (
496
+ fast_store. has( digest) . await ?. is_some( ) ,
497
+ "Expected data to be in the fast store"
498
+ ) ;
499
+ assert ! (
500
+ slow_store. has( digest) . await ?. is_none( ) ,
501
+ "Expected data to not be in the slow store"
502
+ ) ;
503
+ Ok ( ( ) )
504
+ }
505
+
506
+ #[ nativelink_test]
507
+ async fn slow_get_only_not_updated ( ) -> Result < ( ) , Error > {
508
+ let ( fast_slow_store, fast_store, slow_store) =
509
+ make_stores_direction ( StoreDirection :: Both , StoreDirection :: Get ) ;
510
+ let digest = DigestInfo :: try_new ( VALID_HASH , 100 ) . unwrap ( ) ;
511
+ fast_slow_store
512
+ . update_oneshot ( digest, make_random_data ( 100 ) . into ( ) )
513
+ . await ?;
514
+ assert ! (
515
+ fast_store. has( digest) . await ?. is_some( ) ,
516
+ "Expected data to be in the fast store"
517
+ ) ;
518
+ assert ! (
519
+ slow_store. has( digest) . await ?. is_none( ) ,
520
+ "Expected data to not be in the slow store"
521
+ ) ;
522
+ Ok ( ( ) )
523
+ }
524
+
525
+ #[ nativelink_test]
526
+ async fn fast_put_only_not_updated ( ) -> Result < ( ) , Error > {
527
+ let ( fast_slow_store, fast_store, slow_store) =
528
+ make_stores_direction ( StoreDirection :: Update , StoreDirection :: Both ) ;
529
+ let digest = DigestInfo :: try_new ( VALID_HASH , 100 ) . unwrap ( ) ;
530
+ slow_store
531
+ . update_oneshot ( digest, make_random_data ( 100 ) . into ( ) )
532
+ . await ?;
533
+ let _ = fast_slow_store. get_part_unchunked ( digest, 0 , None ) . await ;
534
+ assert ! (
535
+ fast_store. has( digest) . await ?. is_none( ) ,
536
+ "Expected data to not be in the fast store"
537
+ ) ;
538
+ Ok ( ( ) )
539
+ }
0 commit comments