Skip to content

Commit c1ab4f8

Browse files
committed
change syntax inside mock grpc test server - got rid of grpc.Metadata and instead used res.set with Mali, and now the main file is receiving metadata properly
1 parent c52e942 commit c1ab4f8

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

grpc_mockData/server.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ const dataStream = [
3030

3131
// Unary stream
3232
// ctx = watch execution context
33-
function sayHello(ctx) {
33+
async function sayHello(ctx) {
3434
// create new metadata
35-
const metadata = new grpc.Metadata();
36-
metadata.set("it", "works?");
37-
metadata.set("indeed", "it do");
35+
36+
// const metadata = new grpc.Metadata();
37+
ctx.set("it", "works?");
38+
ctx.response.set("indeed", "it do");
3839
// Watcher creates a watch execution context for the watch
3940
// The execution context provides scripts and templates with access to the watch metadata
4041
// console.log("received metadata from client request", ctx.metadata);
@@ -43,12 +44,15 @@ function sayHello(ctx) {
4344

4445
// an alias to ctx.response.res
4546
// This is set only in case of DUPLEX calls, to the the gRPC call reference itself
46-
ctx.res = { message: "Hello " + ctx.req.name };
47-
47+
// ctx.res = { message: "Hello " + ctx.req.name };
48+
ctx.response.res = { message: "Hello " + ctx.req.name };
49+
// ctx.res will do the same as above
50+
console.log("ctx.res", ctx.res);
51+
console.log("ctx.response", ctx.response);
4852
// send response header metadata object directly as an argument and that is set and sent
49-
metadata.set("UNARY", "yes");
50-
ctx.sendMetadata(metadata);
51-
console.log("metadata is", metadata);
53+
// metadata.set("UNARY", "yes");
54+
// ctx.sendMetadata(metadata);
55+
// console.log("metadata is", metadata);
5256
console.log(`set sayHello response from gRPC server: ${ctx.res.message}`);
5357
}
5458
// nested Unary stream

main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@ ipcMain.on("fetch-meta-and-client", (event, data) => {
577577
meta.add(currentHeader.key, currentHeader.value);
578578
}
579579
// just send a hardcoded 'name' - 'test' key value pair
580-
meta.add("name", "SayHello");
580+
// meta.add("name", "SayHello");
581581

582-
console.log("meta is", meta);
582+
console.log("line 582 meta is", meta);
583583

584584
if (rpcType === "UNARY") {
585-
console.log("inside UNARY if statement");
585+
console.log("\n \n inside UNARY if statement");
586586
const query = reqResObj.queryArr[0];
587587
const time = {};
588588

@@ -608,15 +608,15 @@ ipcMain.on("fetch-meta-and-client", (event, data) => {
608608
// store.default.dispatch(actions.reqResUpdate(reqResObj));
609609
}) // metadata from server
610610
.on("metadata", (metadata) => {
611-
console.log("metadata back from server!!");
612-
console.log("the data coming BACK from the server is", metadata);
611+
console.log("\n metadata back from server!! \n");
612+
console.log("\n the data coming BACK from the server is \n", metadata);
613613

614614
// const keys = Object.keys(metadata._internal_repr);
615615
// for (let i = 0; i < keys.length; i += 1) {
616616
// const key = keys[i];
617617
// reqResObj.response.headers[key] = metadata._internal_repr[key][0];
618618
// }
619-
console.log("\n line 611!!! \n");
619+
620620
// store.default.dispatch(actions.reqResUpdate(reqResObj));
621621
});
622622
}

0 commit comments

Comments
 (0)