Skip to content

Commit a58210d

Browse files
committed
Review await test related to core cli plugin, bug still not solved.
1 parent 4b6ebf5 commit a58210d

File tree

6 files changed

+63
-59
lines changed

6 files changed

+63
-59
lines changed

source/tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,5 @@ add_subdirectory(metacall_plugin_extension_test)
233233
add_subdirectory(metacall_plugin_extension_local_test)
234234
add_subdirectory(metacall_plugin_extension_destroy_order_test)
235235
add_subdirectory(metacall_cli_core_plugin_test)
236+
add_subdirectory(metacall_cli_core_plugin_await_test)
236237
add_subdirectory(metacall_backtrace_plugin_test)
237-
add_subdirectory(await_test)

source/tests/await_test/CMakeLists.txt renamed to source/tests/metacall_cli_core_plugin_await_test/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Check if this loader is enabled
2-
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_NODE)
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_NODE)
33
return()
44
endif()
55

@@ -8,7 +8,7 @@ endif()
88
#
99

1010
# Target name
11-
set(target await_test)
11+
set(target metacall-cli-core-plugin-await-test)
1212
message(STATUS "Test ${target}")
1313

1414
#
@@ -32,7 +32,7 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
3232

3333
set(sources
3434
${source_path}/main.cpp
35-
${source_path}/await_test.cpp
35+
${source_path}/metacall_cli_core_plugin_await_test.cpp
3636
)
3737

3838
# Group source files
@@ -96,6 +96,7 @@ target_compile_definitions(${target}
9696
PRIVATE
9797
${DEFAULT_COMPILE_DEFINITIONS}
9898

99+
# Plugin path
99100
METACALL_PLUGIN_PATH="${CMAKE_CURRENT_SOURCE_DIR}/plugins"
100101
)
101102

@@ -140,8 +141,9 @@ add_test(NAME ${target}
140141
add_dependencies(${target}
141142
ext_loader
142143
node_loader
143-
py_loader
144144
plugin_extension
145+
node_port
146+
cli_core_plugin
145147
)
146148

147149
#
@@ -157,4 +159,7 @@ include(TestEnvironmentVariables)
157159
test_environment_variables(${target}
158160
""
159161
${TESTS_ENVIRONMENT_VARIABLES}
162+
163+
# NodeJS Port path
164+
"METACALL_NODE_PORT_PATH=${CMAKE_SOURCE_DIR}/source/ports/node_port/index.js"
160165
)

source/tests/await_test/plugins/await_test/await_test.js renamed to source/tests/metacall_cli_core_plugin_await_test/plugins/await_test/await_test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
const { metacall, metacall_load_from_file, metacall_inspect } = require('metacall')
1+
const { metacall_load_from_file } = require(process.env['METACALL_NODE_PORT_PATH']);
22

33
function await__test(await_cb) {
44
metacall_load_from_file("node", ["scripts/nod.js"]);
55
hello_await = 'hello_boy_await(1,2)';
6+
console.log(await_cb);
7+
8+
// TODO: This call generates a deadlock
69
await_cb(hello_await);
710

811
return 22;

source/tests/await_test/source/await_test.cpp renamed to source/tests/metacall_cli_core_plugin_await_test/source/metacall_cli_core_plugin_await_test.cpp

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
namespace fs = std::filesystem;
2929

30-
class await_test : public testing::Test
30+
class metacall_cli_core_plugin_await_test : public testing::Test
3131
{
3232
public:
3333
};
3434

35-
TEST_F(await_test, DefaultConstructor)
35+
TEST_F(metacall_cli_core_plugin_await_test, DefaultConstructor)
3636
{
3737
metacall_print_info();
3838

@@ -60,56 +60,52 @@ TEST_F(await_test, DefaultConstructor)
6060
metacall_value_destroy(args[1]);
6161
metacall_value_destroy(result);
6262

63-
/* NodeJS */
64-
#if defined(OPTION_BUILD_LOADERS_NODE)
65-
{
66-
/* Get core plugin path and handle in order to load cli plugins */
67-
const char *plugin_path = metacall_plugin_path();
68-
void *plugin_extension_handle = metacall_plugin_extension();
69-
void *cli_plugin_handle = NULL;
70-
71-
if (plugin_path != NULL && plugin_extension_handle != NULL)
72-
{
73-
/* Define the cli plugin path as string (core plugin path plus cli) */
74-
fs::path plugin_cli_path(plugin_path);
75-
plugin_cli_path /= "cli";
76-
std::string plugin_cli_path_str(plugin_cli_path.string());
77-
78-
/* Load cli plugins into plugin cli handle */
79-
void *args[] = {
80-
metacall_value_create_string(plugin_cli_path_str.c_str(), plugin_cli_path_str.length()),
81-
metacall_value_create_ptr(&cli_plugin_handle)
82-
};
83-
84-
void *ret = metacallhv_s(plugin_extension_handle, "plugin_load_from_path", args, sizeof(args) / sizeof(args[0]));
85-
86-
if (ret == NULL || (ret != NULL && metacall_value_to_int(ret) != 0))
87-
{
88-
std::cerr << "Failed to load CLI plugins from folder: " << plugin_cli_path_str << std::endl;
89-
}
90-
91-
metacall_value_destroy(args[0]);
92-
metacall_value_destroy(args[1]);
93-
metacall_value_destroy(ret);
94-
}
95-
96-
void *func = metacall_handle_function(cli_plugin_handle, "await");
97-
if (func == NULL)
98-
std::cerr << "function not in handle\n " << METACALL_PLUGIN_PATH << '\n';
99-
void *args[] = {
100-
metacall_value_create_function(func)
101-
};
102-
void *ret = metacallhv_s(handle, "await__test", args, 1);
103-
104-
EXPECT_NE((void *)NULL, (void *)ret);
105-
106-
EXPECT_EQ((enum metacall_value_id)METACALL_DOUBLE, (enum metacall_value_id)metacall_value_id(ret));
107-
108-
EXPECT_EQ((double)22, (long)metacall_value_to_double(ret));
109-
110-
metacall_value_destroy(ret);
111-
}
112-
#endif /* OPTION_BUILD_LOADERS_NODE */
63+
/* Get core plugin path and handle in order to load cli plugins */
64+
const char *plugin_path = metacall_plugin_path();
65+
void *plugin_extension_handle = metacall_plugin_extension();
66+
void *cli_plugin_handle = NULL;
67+
68+
ASSERT_NE((const char *)plugin_path, (const char *)NULL);
69+
ASSERT_NE((void *)plugin_extension_handle, (void *)NULL);
70+
71+
/* Define the cli plugin path as string (core plugin path plus cli) */
72+
fs::path plugin_cli_path(plugin_path);
73+
plugin_cli_path /= "cli";
74+
std::string plugin_cli_path_str(plugin_cli_path.string());
75+
76+
/* Load cli plugins into plugin cli handle */
77+
void *args_cli[] = {
78+
metacall_value_create_string(plugin_cli_path_str.c_str(), plugin_cli_path_str.length()),
79+
metacall_value_create_ptr(&cli_plugin_handle)
80+
};
81+
82+
result = metacallhv_s(plugin_extension_handle, "plugin_load_from_path", args_cli, sizeof(args_cli) / sizeof(args_cli[0]));
83+
84+
ASSERT_NE((void *)result, (void *)NULL);
85+
ASSERT_EQ((int)0, (int)metacall_value_to_int(result));
86+
87+
metacall_value_destroy(args_cli[0]);
88+
metacall_value_destroy(args_cli[1]);
89+
metacall_value_destroy(result);
90+
91+
void *func = metacall_handle_function(cli_plugin_handle, "await");
92+
93+
ASSERT_NE((void *)func, (void *)NULL);
94+
95+
void *args_test[] = {
96+
metacall_value_create_function(func)
97+
};
98+
99+
result = metacallhv_s(handle, "await__test", args_test, 1);
100+
101+
EXPECT_NE((void *)NULL, (void *)result);
102+
103+
EXPECT_EQ((enum metacall_value_id)METACALL_DOUBLE, (enum metacall_value_id)metacall_value_id(result));
104+
105+
EXPECT_EQ((double)22, (long)metacall_value_to_double(result));
106+
107+
metacall_value_destroy(args_test[0]);
108+
metacall_value_destroy(result);
113109

114110
/* Print inspect information */
115111
{
@@ -125,7 +121,7 @@ TEST_F(await_test, DefaultConstructor)
125121

126122
EXPECT_GT((size_t)size, (size_t)0);
127123

128-
//std::cout << inspect_str << std::endl;
124+
std::cout << inspect_str << std::endl;
129125

130126
metacall_allocator_free(allocator, inspect_str);
131127

0 commit comments

Comments
 (0)