Skip to content

Commit

Permalink
SNOW-1814745-Fix-aborting-requests-in-HttpClient: synchronous test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fpawlowski committed Dec 16, 2024
1 parent cbb3eec commit 196082f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ci/container/hang_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def do_POST(self):
elif self.path.startswith('/xml'):
self.__respond(200, message='<error/>', 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')
Expand Down
32 changes: 29 additions & 3 deletions test/integration/testHttpClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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({
Expand All @@ -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}`);
});
});
});

0 comments on commit 196082f

Please sign in to comment.