Skip to content

Commit 079f631

Browse files
committed
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.
1 parent fbf5562 commit 079f631

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

lib/network/probe/ProbeServer.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ export class ProbeServer extends httpServer {
9090
return;
9191
}
9292

93-
const probeResponse = this._handlers.get(req.url!)!(res, log);
94-
if (probeResponse !== undefined && probeResponse !== '') {
95-
// Return an internal error with the response
96-
errors.InternalError
97-
.customizeDescription(probeResponse)
98-
.writeResponse(res);
99-
}
93+
this._handlers.get(req.url!)!(res, log);
10094
}
10195
}

tests/unit/network/probe/ProbeServer.spec.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,34 @@ describe('network.probe.ProbeServer', () => {
8989
});
9090

9191
it('500 response on bad probe', done => {
92-
server.addHandler('/check', () => 'check failed');
92+
const failedMessage = 'failed_message';
93+
server.addHandler('/check', res => {
94+
res.writeHead(500);
95+
res.end(failedMessage);
96+
});
97+
makeRequest('GET', '/check', (err, res) => {
98+
assert.ifError(err);
99+
assert.strictEqual(res.statusCode, 500);
100+
res.setEncoding('utf8');
101+
res.on('data', body => {
102+
assert.strictEqual(body, failedMessage);
103+
done();
104+
});
105+
});
106+
});
107+
108+
it('500 response on bad async probe', done => {
109+
const failedMessage = 'failed_message';
110+
server.addHandler('/check', async res => {
111+
res.writeHead(500);
112+
res.end(failedMessage);
113+
});
93114
makeRequest('GET', '/check', (err, res) => {
94115
assert.ifError(err);
95116
assert.strictEqual(res.statusCode, 500);
96117
res.setEncoding('utf8');
97118
res.on('data', body => {
98-
assert.strictEqual(
99-
body,
100-
'{"errorType":"InternalError","errorMessage":"check failed"}',
101-
);
119+
assert.strictEqual(body, failedMessage);
102120
done();
103121
});
104122
});

0 commit comments

Comments
 (0)