]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - src/utils.js
Create a constants module to easily modify some constants in a test
[github/Chocobozzz/PeerTube.git] / src / utils.js
index dda6c7a0a7dcb4771c994d256f6cfc1fef04f0cd..5880c6c90409e08ff67febde7fbbe9a22e82d41a 100644 (file)
@@ -10,6 +10,7 @@
   var replay = require('request-replay')
   var ursa = require('ursa')
 
+  var constants = require('./constants')
   var logger = require('./logger')
 
   var utils = {}
       }
     }
 
-    logger.debug('Sending informations to %s.', to_pod.url, { params: params })
-    // Default 10 but in tests we want to be faster
-    var retries = utils.isTestInstance() ? 2 : 10
+    logger.debug('Make retry requests to %s.', to_pod.url)
 
     replay(
       request.post(params, function (err, response, body) {
-        callbackEach(err, response, body, to_pod)
+        callbackEach(err, response, body, params.url, to_pod)
       }),
       {
-        retries: retries,
+        retries: constants.REQUEST_RETRIES,
         factor: 3,
         maxTimeout: Infinity,
         errorCodes: [ 'EADDRINFO', 'ETIMEDOUT', 'ECONNRESET', 'ESOCKETTIMEDOUT', 'ENOTFOUND', 'ECONNREFUSED' ]
@@ -71,8 +70,8 @@
 
     // Make a request for each pod
     async.each(pods, function (pod, callback_each_async) {
-      function callbackEachRetryRequest (err, response, body, pod) {
-        callbackEach(err, response, body, pod, function () {
+      function callbackEachRetryRequest (err, response, body, url, pod) {
+        callbackEach(err, response, body, url, pod, function () {
           callback_each_async()
         })
       }
@@ -84,8 +83,6 @@
 
       // Add data with POST requst ?
       if (all_data.method === 'POST' && all_data.data) {
-        logger.debug('Make a POST request.')
-
         // Encrypt data ?
         if (all_data.encrypt === true) {
           var crt = ursa.createPublicKey(pod.publicKey)
           makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
         }
       } else {
-        logger.debug('Make a GET/DELETE request')
         makeRetryRequest(params, url, pod, signature, callbackEachRetryRequest)
       }
     }, callback)
     process.kill(-webtorrent_process.pid)
   }
 
-  utils.isTestInstance = function () {
-    return (process.env.NODE_ENV === 'test')
-  }
-
   module.exports = utils
 })()