diff --git a/ci/container/hang_webserver.py b/ci/container/hang_webserver.py index 432b649a0..ab25a0152 100755 --- a/ci/container/hang_webserver.py +++ b/ci/container/hang_webserver.py @@ -35,7 +35,7 @@ def do_POST(self): elif self.path.startswith('/xml'): self.__respond(200, message='', content_type='application/xml') elif self.path.startswith('/json'): - self.__respond(200, message='OK', body='{"smkId": 32621973126123526, "data": {"foo":"bar"}}', content_type='application/json') + self.__respond(200, message='OK', body='{"smkId": 32621973126123526, "data": {"test":"data"}}', content_type='application/json') elif self.path.startswith('/resetCounter'): HTTPRequestHandler.counter = 0 self.__respond(200, message='OK') diff --git a/test/integration/testHttpClient.js b/test/integration/testHttpClient.js index deb8bc0a9..a36230522 100644 --- a/test/integration/testHttpClient.js +++ b/test/integration/testHttpClient.js @@ -5,7 +5,7 @@ const { hangWebServerUrl } = require('../hangWebserver'); const assert = require('assert'); const testUtil = require('./testUtil'); -describe('HttpClient Specialized Tests', () => { +describe('HttpClient Tests', () => { let httpClientInstance; const connectionOptions = { @@ -70,8 +70,8 @@ describe('HttpClient Specialized Tests', () => { }); }); - describe('Ensuring normalizeResponse is called for requestAsync', () => { - it('should return a normalized response with statusCode and body', async () => { + describe('Normalizing Response', () => { + it('should return a normalized response with statusCode and body for requestAsync', async () => { const testUrl = hangWebServerUrl + '/json'; const response = await httpClientInstance.requestAsync({ @@ -83,5 +83,31 @@ describe('HttpClient Specialized Tests', () => { assert.ok(response.statusCode, 'Normalized response should have statusCode'); assert.ok(response.body, 'Normalized response should have body'); }); + + it('should return a normalized response with statusCode and body for synchronous request', async () => { + const testUrl = hangWebServerUrl + '/json'; + let errorRaisedInCallback; + + const requestObject = httpClientInstance.request({ + url: testUrl, + method: 'GET', + callback: (err, response) => { + try { + assert.ok(response, 'Response should be defined'); + assert.ok(response.statusCode, 'Normalized response should have statusCode'); + assert.ok(response.body, 'Normalized response should have body'); + } catch (err) { + errorRaisedInCallback = err; + } + } + }); + //Due to usage of 'nextTick' in the httpClient requestPromise may be undefined for some time, only to be set in when scheduled sending took place. + while (!requestObject.requestPromise) { + await testUtil.sleepAsync(1000); + } + await requestObject.requestPromise; + + assert.ok(!errorRaisedInCallback, `Did not receive a normalized response. Error: ${errorRaisedInCallback}`); + }); }); });