@@ -542,6 +542,43 @@ public function test_get_error_count_different_statuses($status): void {
542542 $ this ->assertEquals (0 , $ othercount );
543543 }
544544
545+ /**
546+ * Test that extract_file_contents method handles timeout correctly.
547+ */
548+ public function test_extract_file_contents_handles_timeout (): void {
549+ $ this ->resetAfterTest ();
550+
551+ // Set up Tika configuration.
552+ set_config ('tikahostname ' , 'http://127.0.0.1 ' , 'search_elastic ' );
553+ set_config ('tikaport ' , 9998 , 'search_elastic ' );
554+ set_config ('tikasendsize ' , 512000000 , 'search_elastic ' );
555+ set_config ('timeout ' , 5 , 'search_elastic ' );
556+ set_config ('connecttimeout ' , 2 , 'search_elastic ' );
557+
558+ // Create a test file.
559+ $ file = $ this ->create_test_file ();
560+
561+ // Test with reflection since extract_file_contents is private.
562+ $ reflection = new \ReflectionClass ('search_elastic\local\service\error_service ' );
563+ $ method = $ reflection ->getMethod ('extract_file_contents ' );
564+ $ method ->setAccessible (true );
565+
566+ // Test that request timeout is handled properly and not throw an exception.
567+ $ result = false ;
568+ $ exceptionthrown = false ;
569+
570+ try {
571+ $ result = $ method ->invoke (null , $ file );
572+ $ this ->assertdebuggingcalledcount (1 );
573+ } catch (\Exception $ e ) {
574+ $ exceptionthrown = true ;
575+ }
576+
577+ // Verify that timeout should be handled gracefully, and not crash the indexing task.
578+ $ this ->assertFalse ($ exceptionthrown );
579+ $ this ->assertFalse ($ result );
580+ }
581+
545582 public function tearDown (): void {
546583 parent ::tearDown ();
547584 if ($ this ->generator ) {
0 commit comments