@@ -417,6 +417,69 @@ TEST_F(PythonServerTest, GetProcessFromInitializedPool) {
417417 mgr.shutdown ();
418418}
419419
420+ TEST_F (PythonServerTest, GetProcessRecreatesDeadProcessWhenNoAliveProcess) {
421+ setup_doris_home ();
422+ std::string python_path = create_fake_python_with_socket_creation (" 3.9.16" );
423+
424+ config::max_python_process_num = 1 ;
425+
426+ PythonServerManager mgr;
427+ PythonVersion version (" 3.9.16" , test_dir_, python_path);
428+
429+ ASSERT_TRUE (mgr.ensure_pool_initialized (version).ok ());
430+
431+ ProcessPtr first_process;
432+ ASSERT_TRUE (mgr.get_process (version, &first_process).ok ());
433+ ASSERT_NE (first_process, nullptr );
434+ ASSERT_TRUE (first_process->is_alive ());
435+ pid_t first_pid = first_process->get_child_pid ();
436+
437+ first_process->shutdown ();
438+ ASSERT_FALSE (first_process->is_alive ());
439+
440+ ProcessPtr replacement;
441+ Status status = mgr.get_process (version, &replacement);
442+
443+ EXPECT_TRUE (status.ok ()) << status.to_string ();
444+ ASSERT_NE (replacement, nullptr );
445+ EXPECT_TRUE (replacement->is_alive ());
446+ EXPECT_NE (replacement->get_child_pid (), first_pid);
447+
448+ mgr.shutdown ();
449+ }
450+
451+ TEST_F (PythonServerTest, GetProcessSkipsDeadProcessWhenAliveProcessExists) {
452+ setup_doris_home ();
453+ std::string python_path = create_fake_python_with_socket_creation (" 3.9.16" );
454+
455+ PythonServerManager mgr;
456+ PythonVersion version (" 3.9.16" , test_dir_, python_path);
457+
458+ ProcessPtr alive_process;
459+ ASSERT_TRUE (mgr.fork (version, &alive_process).ok ());
460+ ASSERT_NE (alive_process, nullptr );
461+ ASSERT_TRUE (alive_process->is_alive ());
462+
463+ ProcessPtr dead_process;
464+ ASSERT_TRUE (mgr.fork (version, &dead_process).ok ());
465+ ASSERT_NE (dead_process, nullptr );
466+ pid_t dead_pid = dead_process->get_child_pid ();
467+ dead_process->shutdown ();
468+ ASSERT_FALSE (dead_process->is_alive ());
469+
470+ mgr.process_pools_for_test ()[version] = {alive_process, dead_process};
471+
472+ ProcessPtr selected;
473+ Status status = mgr.get_process (version, &selected);
474+
475+ EXPECT_TRUE (status.ok ()) << status.to_string ();
476+ EXPECT_EQ (selected, alive_process);
477+ EXPECT_FALSE (mgr.process_pools_for_test ()[version][1 ]->is_alive ());
478+ EXPECT_EQ (mgr.process_pools_for_test ()[version][1 ]->get_child_pid (), dead_pid);
479+
480+ mgr.shutdown ();
481+ }
482+
420483TEST_F (PythonServerTest, GetProcessLoadBalancing) {
421484 setup_doris_home ();
422485 std::string python_path = create_fake_python_with_socket_creation (" 3.9.16" );
0 commit comments