@@ -851,6 +851,9 @@ mod tests {
851851
852852 use std:: collections:: HashSet ;
853853
854+ use config:: Config ;
855+ use seqads:: task:: TaskBuilder ;
856+
854857 use crate :: {
855858 tasks:: BlockPairTaskHub ,
856859 test_helper:: { SimpleTask , TempDir } ,
@@ -939,4 +942,44 @@ mod tests {
939942 let _ads_core = AdsCore :: new ( task_hub, & config) ;
940943 // assert_eq!("?", tmp_dir.list().join("\n"));
941944 }
945+
946+ #[ test]
947+ fn test_start_block ( ) {
948+ let ads_dir = "./test_start_block" ;
949+ let _tmp_dir = TempDir :: new ( ads_dir) ;
950+
951+ let config = Config :: from_dir ( ads_dir) ;
952+ AdsCore :: init_dir ( & config) ;
953+
954+ let mut ads = AdsWrap :: new ( & config) ;
955+
956+ for h in 1 ..=3 {
957+ let task_id = h << IN_BLOCK_IDX_BITS ;
958+ let r = ads. start_block (
959+ h,
960+ Arc :: new ( TasksManager :: new (
961+ vec ! [ RwLock :: new( Some (
962+ TaskBuilder :: new( )
963+ . create( & ( h as u64 ) . to_be_bytes( ) , b"v1" )
964+ . build( ) ,
965+ ) ) ] ,
966+ task_id,
967+ ) ) ,
968+ ) ;
969+ assert_eq ! ( r. 0 , true ) ;
970+ if h <= 2 {
971+ assert ! ( r. 1 . is_none( ) ) ;
972+ } else {
973+ assert_eq ! ( r. 1 . as_ref( ) . unwrap( ) . curr_height, 1 ) ;
974+ assert_eq ! ( r. 1 . as_ref( ) . unwrap( ) . extra_data, format!( "height:{}" , 1 ) ) ;
975+ }
976+ let shared_ads = ads. get_shared ( ) ;
977+ shared_ads. insert_extra_data ( h, format ! ( "height:{}" , h) ) ;
978+ shared_ads. add_task ( task_id) ;
979+ }
980+ let r = ads. flush ( ) ;
981+ assert_eq ! ( r. len( ) , 2 ) ;
982+ assert_eq ! ( r[ 0 ] . curr_height, 2 ) ;
983+ assert_eq ! ( r[ 1 ] . curr_height, 3 ) ;
984+ }
942985}
0 commit comments