Fix tests
authorChocobozzz <florian.bigard@gmail.com>
Fri, 30 Oct 2015 17:34:37 +0000 (18:34 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Fri, 30 Oct 2015 17:34:37 +0000 (18:34 +0100)
src/videos.js
src/webTorrentNode.js
test/api/multiplePods.js
test/api/singlePod.js

index 605ce098f1115e415ac6f79a8d47650df8b3a426..48ec19d4d5df05864abfe850104713f410f31777 100644 (file)
 
     VideosDB.findById(id, function (err, video) {
       if (err || !video) {
+        if (!err) err = new Error('Cannot find this video.')
         logger.error('Cannot find this video.', { error: err })
         return callback(err)
       }
index 03bff780381c69619e01149748a9bdc798a31353..ebe8d5d81026217a36cdcc7fab47955369093115 100644 (file)
@@ -8,16 +8,8 @@
 
   var logger = require('./logger')
 
-  var host
-  var port
-
-  try {
-    host = config.get('webserver.host')
-    port = config.get('webserver.port')
-  } catch (e) {
-    host = 'client'
-    port = 1
-  }
+  var host = config.get('webserver.host')
+  var port = config.get('webserver.port')
 
   var nodeKey = 'webtorrentnode' + port
   var processKey = 'webtorrent' + port
   // Useful to kill it
   webtorrentnode.app = null
 
-  webtorrentnode.create = function (callback) {
+  webtorrentnode.create = function (options, callback) {
+    if (typeof options === 'function') {
+      callback = options
+      options = {}
+    }
+
+    // Override options
+    if (options.host) host = options.host
+    if (options.port) {
+      port = options.port
+      nodeKey = 'webtorrentnode' + port
+      processKey = 'webtorrent' + port
+      ipc.config.id = nodeKey
+    }
+
     ipc.serve(function () {
       if (!webtorrentnode.silent) logger.info('IPC server ready.')
 
index fff17900667fdf016c643529a873205c4acc1599..81d4b06b60c60fd452d746e1bb6d3c6f96ae928f 100644 (file)
@@ -61,7 +61,7 @@
                 .end(function (err, res) {
                   if (err) throw err
 
-                  webtorrent.create(function () {
+                  webtorrent.create({ host: 'client', port: '1' }, function () {
                     done()
                   })
                 })
     describe('Should seed the uploaded video', function () {
       it('Should add the file 1 by asking pod 3', function (done) {
         // Yes, this could be long
-        this.timeout(60000)
+        this.timeout(200000)
 
         getVideosList(urls[2], function (err, res) {
           if (err) throw err
 
       it('Should add the file 2 by asking pod 1', function (done) {
         // Yes, this could be long
-        this.timeout(60000)
+        this.timeout(200000)
 
         getVideosList(urls[0], function (err, res) {
           if (err) throw err
 
           var video = res.body[1]
 
-          video_id = video._id
-
           webtorrent.add(video.magnetUri, function (torrent) {
             expect(torrent.files).to.exist
             expect(torrent.files.length).to.equal(1)
 
       it('Should add the file 3 by asking pod 2', function (done) {
         // Yes, this could be long
-        this.timeout(60000)
+        this.timeout(200000)
 
         getVideosList(urls[1], function (err, res) {
           if (err) throw err
 
           var video = res.body[2]
+          video_id = res.body[1]._id
 
           webtorrent.add(video.magnetUri, function (torrent) {
             expect(torrent.files).to.exist
index 59a617970924896147dbe6cf89ad14ae841538d0..149c10b9e1198e809b5d9ec159a126624089c798 100644 (file)
@@ -23,7 +23,7 @@
           app = app1
           url = url1
 
-          webtorrent.create(function () {
+          webtorrent.create({ host: 'client', port: '1' }, function () {
             done()
           })
         })