@@ -847,8 +847,15 @@ pub(super) mod tests {
847847 fetch_task_handle. await . unwrap ( ) ;
848848 }
849849
850- #[ tokio:: test]
851- async fn test_fetch_task_signals_eof ( ) {
850+ /// Spawns a fetch task against a closed shard whose queue holds `num_records` records and whose
851+ /// replication position is `replication_position_inclusive`, then asserts that fetching from
852+ /// `from_position_exclusive` immediately signals EOF at `expected_eof_position`.
853+ async fn check_fetch_task_signals_eof (
854+ num_records : usize ,
855+ replication_position_inclusive : Position ,
856+ from_position_exclusive : Position ,
857+ expected_eof_position : Position ,
858+ ) {
852859 let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
853860 let mrecordlog = Arc :: new ( RwLock :: new ( Some (
854861 MultiRecordLogAsync :: open ( tempdir. path ( ) ) . await . unwrap ( ) ,
@@ -868,26 +875,25 @@ pub(super) mod tests {
868875 . await
869876 . unwrap ( ) ;
870877
871- mrecordlog_guard
872- . as_mut ( )
873- . unwrap ( )
874- . append_records (
875- & queue_id,
876- None ,
877- std:: iter:: once ( MRecord :: new_doc ( "test-doc-foo" ) . encode ( ) ) ,
878- )
879- . await
880- . unwrap ( ) ;
878+ if num_records > 0 {
879+ let records = ( 0 ..num_records) . map ( |_| MRecord :: new_doc ( "test-doc-foo" ) . encode ( ) ) ;
880+ mrecordlog_guard
881+ . as_mut ( )
882+ . unwrap ( )
883+ . append_records ( & queue_id, None , records)
884+ . await
885+ . unwrap ( ) ;
886+ }
881887 drop ( mrecordlog_guard) ;
882888
883889 let open_fetch_stream_request = OpenFetchStreamRequest {
884- client_id : client_id . clone ( ) ,
890+ client_id,
885891 index_uid : Some ( index_uid. clone ( ) ) ,
886892 source_id : source_id. clone ( ) ,
887893 shard_id : Some ( shard_id. clone ( ) ) ,
888- from_position_exclusive : Some ( Position :: offset ( 0u64 ) ) ,
894+ from_position_exclusive : Some ( from_position_exclusive . clone ( ) ) ,
889895 } ;
890- let shard_status = ( ShardState :: Closed , Position :: offset ( 0u64 ) ) ;
896+ let shard_status = ( ShardState :: Closed , replication_position_inclusive ) ;
891897 let ( _shard_status_tx, shard_status_rx) = watch:: channel ( shard_status) ;
892898
893899 let ( mut fetch_stream, fetch_task_handle) = FetchStreamTask :: spawn (
@@ -906,63 +912,56 @@ pub(super) mod tests {
906912 assert_eq ! ( fetch_eof. index_uid( ) , & index_uid) ;
907913 assert_eq ! ( fetch_eof. source_id, source_id) ;
908914 assert_eq ! ( fetch_eof. shard_id( ) , shard_id) ;
909- assert_eq ! ( fetch_eof. eof_position, Some ( Position :: eof( 0u64 ) . as_eof( ) ) ) ;
915+ assert_eq ! (
916+ fetch_eof. eof_position,
917+ Some ( expected_eof_position) ,
918+ "unexpected EOF position when fetching from `{from_position_exclusive:?}`"
919+ ) ;
910920
911921 fetch_task_handle. await . unwrap ( ) ;
912922 }
913923
914924 #[ tokio:: test]
915- async fn test_fetch_task_signals_eof_at_beginning ( ) {
916- let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
917- let mrecordlog = Arc :: new ( RwLock :: new ( Some (
918- MultiRecordLogAsync :: open ( tempdir. path ( ) ) . await . unwrap ( ) ,
919- ) ) ) ;
920- let client_id = "test-client" . to_string ( ) ;
921- let index_uid: IndexUid = IndexUid :: for_test ( "test-index" , 0 ) ;
922- let source_id = "test-source" . to_string ( ) ;
923- let shard_id = ShardId :: from ( 1 ) ;
924- let queue_id = queue_id ( & index_uid, & source_id, & shard_id) ;
925-
926- let open_fetch_stream_request = OpenFetchStreamRequest {
927- client_id : client_id. clone ( ) ,
928- index_uid : Some ( index_uid. clone ( ) ) ,
929- source_id : source_id. clone ( ) ,
930- shard_id : Some ( shard_id. clone ( ) ) ,
931- from_position_exclusive : Some ( Position :: Beginning ) ,
932- } ;
933- let ( shard_status_tx, shard_status_rx) = watch:: channel ( ShardStatus :: default ( ) ) ;
934- let ( mut fetch_stream, fetch_task_handle) = FetchStreamTask :: spawn (
935- open_fetch_stream_request,
936- mrecordlog. clone ( ) ,
937- shard_status_rx,
938- 1024 ,
939- ) ;
940- let mut mrecordlog_guard = mrecordlog. write ( ) . await ;
941-
942- mrecordlog_guard
943- . as_mut ( )
944- . unwrap ( )
945- . create_queue ( & queue_id)
946- . await
947- . unwrap ( ) ;
948- drop ( mrecordlog_guard) ;
925+ async fn test_fetch_task_signals_eof ( ) {
926+ check_fetch_task_signals_eof (
927+ 0 ,
928+ Position :: Beginning ,
929+ Position :: Beginning ,
930+ Position :: Beginning . as_eof ( ) ,
931+ )
932+ . await ;
949933
950- let shard_status = ( ShardState :: Closed , Position :: Beginning ) ;
951- shard_status_tx. send ( shard_status) . unwrap ( ) ;
934+ check_fetch_task_signals_eof (
935+ 0 ,
936+ Position :: Beginning ,
937+ Position :: offset ( 0u64 ) ,
938+ Position :: eof ( 0u64 ) ,
939+ )
940+ . await ;
952941
953- let fetch_message = timeout ( Duration :: from_millis ( 100 ) , fetch_stream. next ( ) )
954- . await
955- . unwrap ( )
956- . unwrap ( )
957- . unwrap ( ) ;
958- let fetch_eof = into_fetch_eof ( fetch_message) ;
942+ check_fetch_task_signals_eof (
943+ 0 ,
944+ Position :: Beginning ,
945+ Position :: offset ( 42u64 ) ,
946+ Position :: eof ( 42u64 ) ,
947+ )
948+ . await ;
959949
960- assert_eq ! ( fetch_eof. index_uid( ) , & index_uid) ;
961- assert_eq ! ( fetch_eof. source_id, source_id) ;
962- assert_eq ! ( fetch_eof. shard_id( ) , shard_id) ;
963- assert_eq ! ( fetch_eof. eof_position, Some ( Position :: Beginning . as_eof( ) ) ) ;
950+ check_fetch_task_signals_eof (
951+ 1 ,
952+ Position :: offset ( 0u64 ) ,
953+ Position :: offset ( 0u64 ) ,
954+ Position :: eof ( 0u64 ) ,
955+ )
956+ . await ;
964957
965- fetch_task_handle. await . unwrap ( ) ;
958+ check_fetch_task_signals_eof (
959+ 1 ,
960+ Position :: offset ( 0u64 ) ,
961+ Position :: offset ( 42u64 ) ,
962+ Position :: eof ( 42u64 ) ,
963+ )
964+ . await ;
966965 }
967966
968967 #[ tokio:: test]
0 commit comments