@@ -72,7 +72,7 @@ It's launching along with the server and even most tests will not use the server
72
72
std::unique_ptr<std::thread> serverThread;
73
73
74
74
class PythonFlowTest : public ::testing::TestWithParam<std::pair<std::string, std::string>> {
75
- protected :
75
+ public :
76
76
static void SetUpTestSuite () {
77
77
std::string configPath = " /ovms/src/test/mediapipe/python/mediapipe_add_python_node.json" ;
78
78
ovms::Server::instance ().setShutdownRequest (0 );
@@ -97,6 +97,8 @@ class PythonFlowTest : public ::testing::TestWithParam<std::pair<std::string, st
97
97
ovms::Server::instance ().setShutdownRequest (1 );
98
98
serverThread->join ();
99
99
ovms::Server::instance ().setShutdownRequest (0 );
100
+ std::string path = std::string (" /tmp/pythonNodeTestRemoveFile.txt" );
101
+ ASSERT_TRUE (!std::filesystem::exists (path));
100
102
}
101
103
};
102
104
@@ -110,6 +112,16 @@ TEST_F(PythonFlowTest, InitializationPass) {
110
112
EXPECT_TRUE (graphDefinition->getStatus ().isAvailable ());
111
113
}
112
114
115
+ TEST_F (PythonFlowTest, FinalizationPass) {
116
+ ModelManager* manager;
117
+ std::string path = std::string (" /tmp/pythonNodeTestRemoveFile.txt" );
118
+ manager = &(dynamic_cast <const ovms::ServableManagerModule*>(ovms::Server::instance ().getModule (SERVABLE_MANAGER_MODULE_NAME))->getServableManager ());
119
+ auto graphDefinition = manager->getMediapipeFactory ().findDefinitionByName (" mediapipePythonBackend" );
120
+ ASSERT_NE (graphDefinition, nullptr );
121
+ EXPECT_TRUE (graphDefinition->getStatus ().isAvailable ());
122
+ ASSERT_TRUE (std::filesystem::exists (path));
123
+ }
124
+
113
125
class DummyMediapipeGraphDefinition : public MediapipeGraphDefinition {
114
126
public:
115
127
std::string inputConfig;
@@ -844,3 +856,110 @@ TEST_F(PythonFlowTest, PythonCalculatorTestSingleInSingleOutMultiRunWithErrors)
844
856
- bad input stream element (py::object that is not pyovms.Tensor)
845
857
- bad output stream element (py::object that is not pyovms.Tensor)
846
858
*/
859
+
860
+ TEST_F (PythonFlowTest, FinalizePassTest) {
861
+ const std::string pbTxt{R"(
862
+ input_stream: "in"
863
+ output_stream: "out"
864
+ node {
865
+ name: "pythonNode2"
866
+ calculator: "PythonBackendCalculator"
867
+ input_side_packet: "PYOBJECT:pyobject"
868
+ input_stream: "in"
869
+ output_stream: "out2"
870
+ node_options: {
871
+ [type.googleapis.com / mediapipe.PythonExecutorCalculatorOptions]: {
872
+ handler_path: "/ovms/src/test/mediapipe/python/scripts/good_finalize_pass.py"
873
+ }
874
+ }
875
+ }
876
+ )" };
877
+ ::mediapipe::CalculatorGraphConfig config;
878
+ ASSERT_TRUE (::google::protobuf::TextFormat::ParseFromString (pbTxt, &config));
879
+
880
+ std::shared_ptr<PythonNodeResource> nodeResource = nullptr ;
881
+ ASSERT_EQ (PythonNodeResource::createPythonNodeResource (nodeResource, config.node (0 ).node_options (0 ), getPythonBackend ()), StatusCode::OK);
882
+ nodeResource->finalize ();
883
+ }
884
+
885
+ TEST_F (PythonFlowTest, FinalizeMissingPassTest) {
886
+ const std::string pbTxt{R"(
887
+ input_stream: "in"
888
+ output_stream: "out"
889
+ node {
890
+ name: "pythonNode2"
891
+ calculator: "PythonBackendCalculator"
892
+ input_side_packet: "PYOBJECT:pyobject"
893
+ input_stream: "in"
894
+ output_stream: "out2"
895
+ node_options: {
896
+ [type.googleapis.com / mediapipe.PythonExecutorCalculatorOptions]: {
897
+ handler_path: "/ovms/src/test/mediapipe/python/scripts/good_finalize_pass.py"
898
+ }
899
+ }
900
+ }
901
+ )" };
902
+ ::mediapipe::CalculatorGraphConfig config;
903
+ ASSERT_TRUE (::google::protobuf::TextFormat::ParseFromString (pbTxt, &config));
904
+
905
+ std::shared_ptr<PythonNodeResource> nodeResource = nullptr ;
906
+ ASSERT_EQ (PythonNodeResource::createPythonNodeResource (nodeResource, config.node (0 ).node_options (0 ), getPythonBackend ()), StatusCode::OK);
907
+ nodeResource->finalize ();
908
+ }
909
+
910
+ TEST_F (PythonFlowTest, FinalizeDestructorRemoveFileTest) {
911
+ const std::string pbTxt{R"(
912
+ input_stream: "in"
913
+ output_stream: "out"
914
+ node {
915
+ name: "pythonNode2"
916
+ calculator: "PythonBackendCalculator"
917
+ input_side_packet: "PYOBJECT:pyobject"
918
+ input_stream: "in"
919
+ output_stream: "out2"
920
+ node_options: {
921
+ [type.googleapis.com / mediapipe.PythonExecutorCalculatorOptions]: {
922
+ handler_path: "/ovms/src/test/mediapipe/python/scripts/good_finalize_remove_file.py"
923
+ }
924
+ }
925
+ }
926
+ )" };
927
+ ::mediapipe::CalculatorGraphConfig config;
928
+ ASSERT_TRUE (::google::protobuf::TextFormat::ParseFromString (pbTxt, &config));
929
+
930
+ std::string path = std::string (" /tmp/pythonNodeTestRemoveFile.txt" );
931
+ {
932
+ std::shared_ptr<PythonNodeResource> nodeResouce = nullptr ;
933
+ ASSERT_EQ (PythonNodeResource::createPythonNodeResource (nodeResouce, config.node (0 ).node_options (0 ), getPythonBackend ()), StatusCode::OK);
934
+
935
+ ASSERT_TRUE (std::filesystem::exists (path));
936
+ // nodeResource destructor calls finalize and removes the file
937
+ }
938
+
939
+ ASSERT_TRUE (!std::filesystem::exists (path));
940
+ }
941
+
942
+ TEST_F (PythonFlowTest, FinalizeException) {
943
+ const std::string pbTxt{R"(
944
+ input_stream: "in"
945
+ output_stream: "out"
946
+ node {
947
+ name: "pythonNode2"
948
+ calculator: "PythonBackendCalculator"
949
+ input_side_packet: "PYOBJECT:pyobject"
950
+ input_stream: "in"
951
+ output_stream: "out2"
952
+ node_options: {
953
+ [type.googleapis.com / mediapipe.PythonExecutorCalculatorOptions]: {
954
+ handler_path: "/ovms/src/test/mediapipe/python/scripts/bad_finalize_exception.py"
955
+ }
956
+ }
957
+ }
958
+ )" };
959
+ ::mediapipe::CalculatorGraphConfig config;
960
+ ASSERT_TRUE (::google::protobuf::TextFormat::ParseFromString (pbTxt, &config));
961
+
962
+ std::shared_ptr<PythonNodeResource> nodeResource = nullptr ;
963
+ ASSERT_EQ (PythonNodeResource::createPythonNodeResource (nodeResource, config.node (0 ).node_options (0 ), getPythonBackend ()), StatusCode::OK);
964
+ nodeResource->finalize ();
965
+ }
0 commit comments