Add tests for HTTP 408 retry logic

This commit is contained in:
Jianghao Lu 2014-10-01 15:12:22 -07:00
Родитель 75802486cf
Коммит 790ffca5c2
5 изменённых файлов: 155 добавлений и 3 удалений

Просмотреть файл

@ -24,7 +24,7 @@ var azureutil = require('../../util/util');
* @return {bool} True if the operation qualifies for a retry; false otherwise.
*/
function shouldRetry(statusCode, retryData) {
if (statusCode < 500) {
if (statusCode < 500 && statusCode != 408) {
return false;
}

Просмотреть файл

@ -24,7 +24,7 @@ var azureutil = require('../../util/util');
* @return {bool} True if the operation qualifies for a retry; false otherwise.
*/
function shouldRetry(statusCode, retryData) {
if (statusCode >= 400 && statusCode < 500) {
if (statusCode < 500 && statusCode != 408) {
return false;
}

Просмотреть файл

@ -0,0 +1,77 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
var assert = require('assert');
// Test includes
var testutil = require('../../util/util');
// Lib includes
var azure = testutil.libRequire('azure');
var ExponentialRetryPolicyFilter = azure.ExponentialRetryPolicyFilter;
suite('exponentialretrypolicyfilter-unittests', function () {
test('RetrySucceedsOnHttp408StatusCode', function (done) {
var retryCount = 2;
var retryInterval = 2;
var minRetryInterval = 1;
var maxRetryInterval = 10;
var response = {'statusCode': 408};
var mockNextGenerator = function() {
var timesCalled = 0;
return function(options, retryCallback) {
if (timesCalled == 0) {
timesCalled ++;
retryCallback(true, response, null);
} else {
done();
}
};
};
var mockRetryPolicyFilter = new ExponentialRetryPolicyFilter(retryCount, retryInterval, minRetryInterval, maxRetryInterval);
mockRetryPolicyFilter(null, mockNextGenerator(), function(err, result, response, body) {
throw "Fail to retry on HTTP 408";
});
});
test('DoesNotRetryOnHttp404StatusCode', function (done) {
var retryCount = 2;
var retryInterval = 2;
var minRetryInterval = 1;
var maxRetryInterval = 10;
var response = {'statusCode': 404};
var mockNextGenerator = function() {
var timesCalled = 0;
return function(options, retryCallback) {
if (timesCalled == 0) {
timesCalled ++;
retryCallback(true, response, null);
} else {
throw "Fail to retry on HTTP 408";
}
};
};
var mockRetryPolicyFilter = new ExponentialRetryPolicyFilter(retryCount, retryInterval, minRetryInterval, maxRetryInterval);
mockRetryPolicyFilter(null, mockNextGenerator(), function(err, result, response, body) {
done();
});
});
});

Просмотреть файл

@ -0,0 +1,73 @@
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
var assert = require('assert');
// Test includes
var testutil = require('../../util/util');
// Lib includes
var azure = testutil.libRequire('azure');
var LinearRetryPolicyFilter = azure.LinearRetryPolicyFilter;
suite('linearretrypolicyfilter-unittests', function () {
test('RetrySucceedsOnHttp408StatusCode', function (done) {
var retryCount = 2;
var retryInterval = 1;
var response = {'statusCode': 408};
var mockNextGenerator = function() {
var timesCalled = 0;
return function(options, retryCallback) {
if (timesCalled == 0) {
timesCalled ++;
retryCallback(true, null, response, null);
} else {
done();
}
};
};
var mockRetryPolicyFilter = new LinearRetryPolicyFilter(retryCount, retryInterval);
mockRetryPolicyFilter(null, mockNextGenerator(), function(err, result, response, body) {
throw "Fail to retry on HTTP 408";
});
});
test('DoesNotRetryOnHttp404StatusCode', function (done) {
var retryCount = 2;
var retryInterval = 1;
var response = {'statusCode': 404};
var mockNextGenerator = function() {
var timesCalled = 0;
return function(options, retryCallback) {
if (timesCalled == 0) {
timesCalled ++;
retryCallback(true, null, response, null);
} else {
throw "Fail to retry on HTTP 408";
}
};
};
var mockRetryPolicyFilter = new LinearRetryPolicyFilter(retryCount, retryInterval);
mockRetryPolicyFilter(null, mockNextGenerator(), function(err, result, response, body) {
done();
});
});
});

Просмотреть файл

@ -1,4 +1,6 @@
common/credentials/token-tests.js
common/filters/linearretrypolicyfilter-unittests.js
common/filters/exponentialretrypolicyfilter-unittests.js
common/filters/exponentialretrypolicyfilter-tests.js
common/filters/linearretrypolicyfilter-tests.js
common/filters/proxyfilter-tests.js
@ -62,4 +64,4 @@ services/HDInsight/hdinsight-createCluster-unit-tests.js
services/HDInsight/hdinsight-deleteCluster-unit-tests.js
services/HDInsight/namespace-tests.js
# These tests are waiting for the CI system to get the proper setup.
# services/HDInsight/hdinsight-tests.js
# services/HDInsight/hdinsight-tests.js