Skip to content

Commit 0ff9225

Browse files
committed
Solve deadlock in metacall node port test.
1 parent 8032b37 commit 0ff9225

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

source/ports/node_port/test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const waitForMocha = async () => {
4141
return new Promise((resolve, reject) => mocha.run(failures => failures ? reject(failures) : resolve()));
4242
};
4343

44-
void (async () => {
44+
const main = async () => {
4545
try {
4646
// Run the tests
4747
await waitForMocha();
@@ -51,5 +51,18 @@ void (async () => {
5151
}
5252
}
5353

54-
console.log('Tests passed without errors');
55-
})();
54+
return 'Tests passed without errors';
55+
};
56+
57+
/* Allow to execute the test on demand */
58+
if (process.env['NODE_PORT_TEST_EXPORTS']) {
59+
/* Export the test as a function */
60+
module.exports = {
61+
main,
62+
};
63+
} else {
64+
/* Execute the test and print the result */
65+
void (async () => {
66+
console.log(await main());
67+
})();
68+
}

source/tests/metacall_node_port_test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,4 +240,5 @@ test_environment_variables(${target}
240240
${TESTS_ENVIRONMENT_VARIABLES_C}
241241
${TESTS_ENVIRONMENT_VARIABLES_RS}
242242
${TESTS_ENVIRONMENT_VARIABLES_OPENSSL}
243+
"NODE_PORT_TEST_EXPORTS=1"
243244
)

source/tests/metacall_node_port_test/source/metacall_node_port_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ TEST_F(metacall_node_port_test, DefaultConstructor)
7575

7676
void *future = metacall_await("main", metacall_null_args, accept, reject, static_cast<void *>(&await_data));
7777

78-
await_data.c.wait(lock);
78+
ASSERT_NE((void *)NULL, (void *)future);
7979

80-
EXPECT_NE((void *)NULL, (void *)future);
80+
ASSERT_EQ((enum metacall_value_id)metacall_value_id(future), (enum metacall_value_id)METACALL_FUTURE);
8181

82-
EXPECT_EQ((enum metacall_value_id)metacall_value_id(future), (enum metacall_value_id)METACALL_FUTURE);
82+
await_data.c.wait(lock);
8383

8484
metacall_value_destroy(future);
8585
}

0 commit comments

Comments
 (0)