MCPcopy Create free account
hub / github.com/TuGraph-family/tugraph-db / TEST_F

Function TEST_F

test/test_python_plugin_manager_impl.cpp:153–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151}
152
153TEST_F(TestPythonPluginManagerImpl, PythonPluginManagerImpl) {
154 using namespace fma_common;
155 using namespace lgraph;
156 std::string plugin_dir = "./python_plugin";
157 std::string db_dir = "./testdb";
158 int n_processes = 3;
159 int max_idle_seconds = 2;
160 int max_plugin_lifetime_seconds = 10 * max_idle_seconds;
161 int argc = _ut_argc;
162 char** argv = _ut_argv;
163 Configuration config;
164 config.Add(db_dir, "db", true).Comment("DB dir");
165 config.Add(plugin_dir, "plugin", true).Comment("Plugin dir");
166 config.Add(n_processes, "n,processes", true).Comment("Number of processes");
167 config.Add(max_idle_seconds, "i,idle", true).Comment("Max idle seconds for python process");
168 config.Add(max_plugin_lifetime_seconds, "lifetime", true)
169 .Comment("Max life time for python process to be reused");
170 config.ParseAndFinalize(argc, argv);
171 fma_common::file_system::RemoveDir(db_dir);
172
173 Galaxy galaxy(db_dir);
174 std::string user = "admin";
175 AccessControlledDB db = galaxy.OpenGraph(user, "default");
176
177 {
178 UT_WARN() << "Testing load plugin";
179 Tester manager(db_dir, (size_t)1 << 30, plugin_dir, max_idle_seconds,
180 max_plugin_lifetime_seconds);
181 fma_common::FileSystem::GetFileSystem("./").Mkdir(plugin_dir);
182 WriteEchoPlugin(plugin_dir + "/echo.so");
183 auto* pinfo = manager.CreatePluginInfo();
184 pinfo->read_only = true;
185 manager.LoadPlugin(user, "echo", pinfo);
186 // current implementation allows repeated load
187 manager.LoadPlugin(user, "echo", pinfo);
188
189 UT_LOG() << "Testing call plugin";
190 std::string output;
191
192 manager.DoCall(nullptr, user, &db, "echo", pinfo, "hello", 0, true, output);
193 UT_EXPECT_EQ(output, "hello");
194
195 // currently delete has no effect, just return success
196 UT_LOG() << "Testing del plugin";
197 manager.UnloadPlugin(user, "echo", pinfo);
198
199 // since delete has no effect, this should work
200 UT_LOG() << "Testing call plugin";
201 manager.DoCall(nullptr, user, &db, "echo", pinfo, "hello", 0, true, output);
202 UT_EXPECT_EQ(output, "hello");
203
204 // test timeout
205 UT_LOG() << "Testing timeout with sleep";
206 delete pinfo;
207 pinfo = manager.CreatePluginInfo();
208 WriteSleepPlugin(plugin_dir + "/sleep.so");
209 manager.LoadPlugin(user, "sleep", pinfo);
210 UT_LOG() << "Calling sleep for 0.1";

Callers

nothing calls this directly

Calls 15

RemoveDirFunction · 0.85
WriteEchoPluginFunction · 0.85
WriteSleepPluginFunction · 0.85
SleepSFunction · 0.85
ParseAndFinalizeMethod · 0.80
GetNFreeMethod · 0.80
UT_EXPECT_ANY_THROWFunction · 0.70
to_stringFunction · 0.50
AddMethod · 0.45
OpenGraphMethod · 0.45
MkdirMethod · 0.45
CreatePluginInfoMethod · 0.45

Tested by

no test coverage detected