Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ import { startBlockedMonitor } from './utils/blockedMonitor';
import { isEnvironmentVariableSet } from './utils/util';

export function startNodeWorker(args) {
const { host, port, workerId, requestId, grpcMaxMessageLength } = parseArgs(args.slice(2));
if (!host || !port || !workerId || !requestId || !grpcMaxMessageLength) {
const parsedArgs = parseArgs(args.slice(2));
const uri = parsedArgs['functions-uri'];
const workerId = parsedArgs['functions-worker-id'];
const requestId = parsedArgs['functions-request-id'];
const grpcMaxMessageLength = parsedArgs['functions-grpc-max-message-length'];
if (!uri || !workerId || !requestId || !grpcMaxMessageLength) {
systemLog(
'usage --host hostName --port portNumber --workerId workerId --requestId requestId --grpcMaxMessageLength grpcMaxMessageLength'
'usage --functions-uri uri --functions-worker-id workerId --functions-request-id requestId --functions-grpc-max-message-length grpcMaxMessageLength'
);
// Find which arguments are in error
const debugInfo: string[] = [];
if (!host) debugInfo.push(`'hostName' is ${host}`);
if (!port) debugInfo.push(`'port' is ${port}`);
if (!workerId) debugInfo.push(`'workerId' is ${workerId}`);
if (!requestId) debugInfo.push(`'requestId' is ${requestId}`);
if (!grpcMaxMessageLength) debugInfo.push(`'grpcMaxMessageLength' is ${grpcMaxMessageLength}`);
if (!uri) debugInfo.push(`'functions-uri' is ${uri}`);
if (!workerId) debugInfo.push(`'functions-worker-id' is ${workerId}`);
if (!requestId) debugInfo.push(`'functions-request-id' is ${requestId}`);
if (!grpcMaxMessageLength) debugInfo.push(`'functions-grpc-max-message-length' is ${grpcMaxMessageLength}`);

throw new AzFuncSystemError(`gRPC client connection info is missing or incorrect (${debugInfo.join(', ')}).`);
}
worker.id = workerId;

const connection = `${host}:${port}`;
const connection = new URL(uri).host;
systemLog(`Worker ${workerId} connecting on ${connection}`);

try {
Expand Down
26 changes: 11 additions & 15 deletions test/Worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,35 @@ describe('Worker', () => {
const args = [
'/node',
'nodejsWorker.js',
'--host',
'120.0.0.0',
'--port',
'8000',
'--workerId',
'--functions-uri',
'http://127.0.0.1:58870/',
'--functions-worker-id',
'bd2e3e80-46ba',
'--requestId',
'--functions-request-id',
'bd2e3e80-46ba',
'--grpcMaxMessageLength',
'--functions-grpc-max-message-length',
'0',
];
expect(() => {
startNodeWorker(args);
}).to.throw("gRPC client connection info is missing or incorrect ('grpcMaxMessageLength' is 0).");
}).to.throw("gRPC client connection info is missing or incorrect ('functions-grpc-max-message-length' is 0).");
});

it('throws error on incorrect args: grpcMaxMessageLength 0 and null requestId', () => {
const args = [
'/node',
'nodejsWorker.js',
'--host',
'120.0.0.0',
'--port',
'8000',
'--workerId',
'--functions-uri',
'http://127.0.0.1:58870/',
'--functions-worker-id',
'bd2e3e80-46ba',
'--grpcMaxMessageLength',
'--functions-grpc-max-message-length',
'0',
];
expect(() => {
startNodeWorker(args);
}).to.throw(
"gRPC client connection info is missing or incorrect ('requestId' is undefined, 'grpcMaxMessageLength' is 0)."
"gRPC client connection info is missing or incorrect ('functions-request-id' is undefined, 'functions-grpc-max-message-length' is 0)."
);
});
});