|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | var request = require('../'); |
| 4 | +const http = require('http'); |
4 | 5 | var t = require('chai').assert; |
5 | 6 |
|
6 | 7 | describe('RetryStrategies', function () { |
@@ -43,6 +44,38 @@ describe('RetryStrategies', function () { |
43 | 44 | }); |
44 | 45 | }); |
45 | 46 |
|
| 47 | + it('should not clone `options.agent`', function (done) { |
| 48 | + const agent = new http.Agent({ keepAlive: true }); |
| 49 | + const cloneable = { a: true }; |
| 50 | + var strategy = function (err, response, body, options) { |
| 51 | + options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200 |
| 52 | + t.strictEqual(agent, options.agent); |
| 53 | + t.deepEqual(cloneable, options.cloneable); |
| 54 | + t.notEqual(cloneable, options.cloneable); |
| 55 | + return { |
| 56 | + mustRetry: true, |
| 57 | + options: options, |
| 58 | + }; |
| 59 | + }; |
| 60 | + |
| 61 | + request({ |
| 62 | + url: 'http://www.filltext.com/?rows=1&err=500', // returns a 500 status |
| 63 | + maxAttempts: 3, |
| 64 | + agent: agent, |
| 65 | + retryDelay: 100, |
| 66 | + cloneable: cloneable, |
| 67 | + retryStrategy: strategy |
| 68 | + }, function(err, response, body) { |
| 69 | + if(err) done(err); |
| 70 | + |
| 71 | + t.strictEqual(200, response.statusCode); |
| 72 | + t.strictEqual(agent, this.options.agent); |
| 73 | + t.deepEqual(cloneable, this.options.cloneable); |
| 74 | + t.notEqual(cloneable, this.options.cloneable); |
| 75 | + done(); |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
46 | 79 | it('should not overwrite `options` object if strategy did not returned it', function (done) { |
47 | 80 | var strategy = function (err, response, body, options) { |
48 | 81 | options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200 |
|
0 commit comments