1 // This test checks that the interaction between NodeServer.execute defined in
2 // httpd.js and the node server that we're interacting with defined in
3 // moz-http2.js is working properly.
4 /* global my_defined_var */
8 add_task(async
function test_execute() {
12 let id
= await NodeServer
.fork();
13 equal(await NodeServer
.execute(id
, `"hello"`), "hello");
14 equal(await NodeServer
.execute(id
, `(() => "hello")()`), "hello");
15 equal(await NodeServer
.execute(id
, `my_defined_var = 1;`), 1);
16 equal(await NodeServer
.execute(id
, `(() => my_defined_var)()`), 1);
17 equal(await NodeServer
.execute(id
, `my_defined_var`), 1);
19 await NodeServer
.execute(id
, `not_defined_var`)
21 ok(false, "should have thrown");
24 equal(e
.message
, "ReferenceError: not_defined_var is not defined");
26 e
.stack
.includes("moz-http2-child.js"),
27 `stack should be coming from moz-http2-child.js - ${e.stack}`
30 await NodeServer
.execute("definitely_wrong_id", `"hello"`)
32 ok(false, "should have thrown");
35 equal(e
.message
, "Error: could not find id");
37 e
.stack
.includes("moz-http2.js"),
38 `stack should be coming from moz-http2.js - ${e.stack}`
42 // Defines f in the context of the node server.
43 // The implementation of NodeServer.execute prepends `functionName =` to the
44 // body of the function we pass so it gets attached to the global context
46 equal(await NodeServer
.execute(id
, f
), undefined);
47 equal(await NodeServer
.execute(id
, `f()`), "bla");
51 return my_defined_var
;
55 equal(await NodeServer
.execute(id
, myClass
), undefined);
56 equal(await NodeServer
.execute(id
, `myClass.doStuff()`), 1);
58 equal(await NodeServer
.kill(id
), undefined);
59 await NodeServer
.execute(id
, `f()`)
60 .then(() => ok(false, "should throw"))
61 .catch(e
=> equal(e
.message
, "Error: could not find id"));
62 id
= await NodeServer
.fork();
63 // Check that a child process dying during a call throws an error.
64 await NodeServer
.execute(id
, `process.exit()`)
65 .then(() => ok(false, "should throw"))
67 equal(e
.message
, "child process exit closing code: 0 signal: null")
70 id
= await NodeServer
.fork();
72 await NodeServer
.execute(
74 `setTimeout(function() { sendBackResponse(undefined) }, 0); 2`
78 await
new Promise(resolve
=> do_timeout(10, resolve
));
79 await NodeServer
.kill(id
)
80 .then(() => ok(false, "should throw"))
84 `forked process without handler sent: {"error":"","errorStack":""}\n`