Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_node_execute.js
blob3640514a8e7ecdb0ace86a68280e5449ceca0e8a
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 */
6 "use strict";
8 add_task(async function test_execute() {
9 function f() {
10 return "bla";
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`)
20 .then(() => {
21 ok(false, "should have thrown");
23 .catch(e => {
24 equal(e.message, "ReferenceError: not_defined_var is not defined");
25 ok(
26 e.stack.includes("moz-http2-child.js"),
27 `stack should be coming from moz-http2-child.js - ${e.stack}`
29 });
30 await NodeServer.execute("definitely_wrong_id", `"hello"`)
31 .then(() => {
32 ok(false, "should have thrown");
34 .catch(e => {
35 equal(e.message, "Error: could not find id");
36 ok(
37 e.stack.includes("moz-http2.js"),
38 `stack should be coming from moz-http2.js - ${e.stack}`
40 });
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
45 // in the server.
46 equal(await NodeServer.execute(id, f), undefined);
47 equal(await NodeServer.execute(id, `f()`), "bla");
49 class myClass {
50 static doStuff() {
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"))
66 .catch(e =>
67 equal(e.message, "child process exit closing code: 0 signal: null")
70 id = await NodeServer.fork();
71 equal(
72 await NodeServer.execute(
73 id,
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"))
81 .catch(e =>
82 equal(
83 e.message,
84 `forked process without handler sent: {"error":"","errorStack":""}\n`
87 });