From 079f631711712ce774a8353b4726b0f482e4a18c Mon Sep 17 00:00:00 2001 From: Nicolas Humbert Date: Wed, 29 Nov 2023 14:43:49 +0100 Subject: [PATCH 1/2] ARSN-376 Probe response logic should be handled in the handler Currently, the probe response logic is distributed between Backbeat probe handlers and Arsenal's onRequest method. This scattered approach causes confusion for developers and results in bugs. The solution is to centralize the probe response logic exclusively within the Backbeat probe handlers. --- lib/network/probe/ProbeServer.ts | 8 +----- tests/unit/network/probe/ProbeServer.spec.js | 28 ++++++++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/network/probe/ProbeServer.ts b/lib/network/probe/ProbeServer.ts index 32fb14b26..1e7e4b5ab 100644 --- a/lib/network/probe/ProbeServer.ts +++ b/lib/network/probe/ProbeServer.ts @@ -90,12 +90,6 @@ export class ProbeServer extends httpServer { return; } - const probeResponse = this._handlers.get(req.url!)!(res, log); - if (probeResponse !== undefined && probeResponse !== '') { - // Return an internal error with the response - errors.InternalError - .customizeDescription(probeResponse) - .writeResponse(res); - } + this._handlers.get(req.url!)!(res, log); } } diff --git a/tests/unit/network/probe/ProbeServer.spec.js b/tests/unit/network/probe/ProbeServer.spec.js index 3f0a74625..12d58db65 100644 --- a/tests/unit/network/probe/ProbeServer.spec.js +++ b/tests/unit/network/probe/ProbeServer.spec.js @@ -89,16 +89,34 @@ describe('network.probe.ProbeServer', () => { }); it('500 response on bad probe', done => { - server.addHandler('/check', () => 'check failed'); + const failedMessage = 'failed_message'; + server.addHandler('/check', res => { + res.writeHead(500); + res.end(failedMessage); + }); + makeRequest('GET', '/check', (err, res) => { + assert.ifError(err); + assert.strictEqual(res.statusCode, 500); + res.setEncoding('utf8'); + res.on('data', body => { + assert.strictEqual(body, failedMessage); + done(); + }); + }); + }); + + it('500 response on bad async probe', done => { + const failedMessage = 'failed_message'; + server.addHandler('/check', async res => { + res.writeHead(500); + res.end(failedMessage); + }); makeRequest('GET', '/check', (err, res) => { assert.ifError(err); assert.strictEqual(res.statusCode, 500); res.setEncoding('utf8'); res.on('data', body => { - assert.strictEqual( - body, - '{"errorType":"InternalError","errorMessage":"check failed"}', - ); + assert.strictEqual(body, failedMessage); done(); }); }); From 06244059a824abba008890c98ef20d127344c53a Mon Sep 17 00:00:00 2001 From: Nicolas Humbert Date: Thu, 30 Nov 2023 14:48:07 +0100 Subject: [PATCH 2/2] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a8f3ae639..5d661535b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "engines": { "node": ">=16" }, - "version": "7.10.49", + "version": "7.10.50", "description": "Common utilities for the S3 project components", "main": "build/index.js", "repository": {