Skip to content

Commit

Permalink
fix: Slow startup time/recursive search. Ref #83 (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhendumadhukar authored Aug 3, 2021
1 parent 3ae339d commit 2c64bbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"max-classes-per-file": "error",
"max-depth": "off",
"max-len": "off",
"max-lines": "error",
"max-lines": "off",
"max-lines-per-function": "off",
"max-nested-callbacks": "error",
"max-params": "off",
Expand Down
5 changes: 0 additions & 5 deletions src/parser/HttpParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,6 @@ export class HttpParser {
case "ERR_EMPTY_RESPONSE":
this.res.socket.destroy()
break;
// case "ERR_INVALID_HTTP_RESPONSE":
// this.res.socket.cork();
// this.res.socket.write(Buffer.from("123sdlyndb;aie10-)(&2*2++1dnb/vlaj", 'utf-8'));
// this.res.socket.end();
// break;
case "ERR_INCOMPLETE_CHUNKED_ENCODING":
this.res.writeHead(200);
this.res.write('123sdlyndb;aie10-)(&2*2++1dnb/vlaj');
Expand Down
69 changes: 28 additions & 41 deletions src/protocols/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import express from "express";
// @ts-ignore
import jp from 'jsonpath';
import fs from "fs";
import path from "path";
import http from "http";
Expand Down Expand Up @@ -109,53 +111,38 @@ export default class Protocols {
logger.info(`Worker sharing gRPC server at ${grpcHost}:${grpcPort} ⛳`);
server.start();
});
packages.forEach((pkg: any) => {
let services: any[] = [];
let getObject = function (pkg: any) {
for (var prop in pkg) {
if (prop == 'service') {
services.push(pkg[prop]);
break;
const services: any[] = jp.query(packages, "$..service");
services.forEach((service) => {
let methods = Object.keys(service);
methods.forEach((method) => {
if (!service[method]["responseStream"] && !service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMock, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'unary')) {
logger.debug(`Registering Unary method: ${method}`);
} else {
if (pkg[prop] instanceof Object) {
getObject(pkg[prop]);
}
logger.warn(`Not re-registering ${method}. Already registered.`)
}
}
}
getObject(pkg);
services.forEach((service) => {
let methods = Object.keys(service);
methods.forEach((method) => {
if (!service[method]["responseStream"] && !service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMock, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'unary')) {
logger.debug(`Registering Unary method: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
}
if (service[method]["responseStream"] && !service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockServerStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'serverStream')) {
logger.debug(`Registering method with server side streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
if (service[method]["responseStream"] && !service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockServerStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'serverStream')) {
logger.debug(`Registering method with server side streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
if (!service[method]["responseStream"] && service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockClientStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'clientStream')) {
logger.debug(`Registering method with client side streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
}
if (!service[method]["responseStream"] && service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockClientStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'clientStream')) {
logger.debug(`Registering method with client side streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
if (service[method]["responseStream"] && service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockBidiStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'bidi')) {
logger.debug(`Registering method with BIDI streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
}
if (service[method]["responseStream"] && service[method]["requestStream"]) {
if (server.register(service[method]["path"], grpcParser.camouflageMockBidiStream, service[method]["responseSerialize"], service[method]["requestDeserialize"], 'bidi')) {
logger.debug(`Registering method with BIDI streaming: ${method}`);
} else {
logger.warn(`Not re-registering ${method}. Already registered.`)
}
});
}
});
});
};
Expand Down

0 comments on commit 2c64bbe

Please sign in to comment.