@@ -8,6 +8,9 @@ import metacall.instances._
88import metacall .util ._
99import org .scalatest .flatspec .AnyFlatSpec
1010
11+ import java .util .concurrent .locks .{ReentrantLock }
12+ import java .util .concurrent .atomic .{AtomicBoolean }
13+
1114class MetaCallSpecRunner {
1215 def run () = {
1316 println(" Executing MetaCallSpec Tests" )
@@ -31,28 +34,75 @@ class MetaCallSpec extends AnyFlatSpec {
3134 }
3235 }
3336
34- // "MetaCall" should "load node script successsfully" in {
35- // // NodeJS requires to set the library path environment variable
36- // assert(
37- // sys.env.get("LOADER_LIBRARY_PATH").map(_ != "").getOrElse(false),
38- // "For running NodeJS tests you must define the loader library path"
39- // )
40-
41- // val scriptPaths = Array(
42- // Paths.get("./src/test/scala/scripts/main.js").toAbsolutePath.toString()
43- // )
44- // val retCode = metacall.metacall_load_from_file(
45- // "node",
46- // scriptPaths,
47- // SizeT(scriptPaths.length.toLong),
48- // null
49- // )
50-
51- // require(
52- // retCode == 0,
53- // s"MetaCall failed to load the script with code $retCode"
54- // )
55- // }
37+ " MetaCall" should " load node script successsfully" in {
38+ // NodeJS requires to set the library path environment variable
39+ assert(
40+ sys.env.get(" LOADER_LIBRARY_PATH" ).map(_ != " " ).getOrElse(false ),
41+ " For running NodeJS tests you must define the loader library path"
42+ )
43+
44+ val scriptPaths = Array (
45+ Paths .get(" ./src/test/scala/scripts/main.js" ).toAbsolutePath.toString()
46+ )
47+ val retCode = metacall.metacall_load_from_file(
48+ " node" ,
49+ scriptPaths,
50+ SizeT (scriptPaths.length.toLong),
51+ null
52+ )
53+
54+ require(
55+ retCode == 0 ,
56+ s " MetaCall failed to load the script with code $retCode"
57+ )
58+
59+ val awaitLock = new ReentrantLock ()
60+ val awaitCond = awaitLock.newCondition()
61+ val resolved = new AtomicBoolean (false )
62+
63+ awaitLock.lock()
64+
65+ val argPtr = metacall.metacall_value_create_int(1000 )
66+ val ret = metacall.metacall_await_s(
67+ " sleep" ,
68+ Array (argPtr),
69+ SizeT (1 ),
70+ new metacall.ResolveCallback () {
71+ def invoke (result : Pointer , data : Pointer ): Pointer = {
72+ awaitLock.lock()
73+ resolved.set(true )
74+ awaitCond.signal()
75+ awaitLock.unlock()
76+ null
77+ }
78+ },
79+ new metacall.RejectCallback () {
80+ def invoke (result : Pointer , data : Pointer ): Pointer = {
81+ awaitLock.lock()
82+ resolved.set(false )
83+ awaitCond.signal()
84+ awaitLock.unlock()
85+ null
86+ }
87+ },
88+ null
89+ )
90+
91+ awaitCond.await()
92+ awaitLock.unlock()
93+
94+ require(
95+ resolved.get() == true ,
96+ " Await was not resolved succesfully"
97+ )
98+
99+ require(
100+ metacall.metacall_value_id(ret) == 12 , // METACALL_FUTURE
101+ " Invalid return value from metacall await"
102+ )
103+
104+ metacall.metacall_value_destroy(ret)
105+ }
56106
57107 " MetaCall" should " load python script successsfully" in {
58108 val scriptPaths = Array (
0 commit comments