From fce897f326af14406ced2f71a00ae89ff297a550 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 4 May 2017 21:51:00 +0200 Subject: [PATCH] Server: add tests to video transcoder --- config/default.yaml | 2 +- config/test-2.yaml | 3 + config/test-6.yaml | 3 - server/tests/api/index.js | 1 + server/tests/api/video-transcoder.js | 115 +++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 server/tests/api/video-transcoder.js diff --git a/config/default.yaml b/config/default.yaml index 27eb2a533..e03bf1aea 100644 --- a/config/default.yaml +++ b/config/default.yaml @@ -32,5 +32,5 @@ signup: # If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag # Uses a lot of CPU! transcoding: - enabled: true + enabled: false threads: 2 diff --git a/config/test-2.yaml b/config/test-2.yaml index 77b2d6095..c95b9c229 100644 --- a/config/test-2.yaml +++ b/config/test-2.yaml @@ -21,3 +21,6 @@ admin: signup: enabled: false + +transcoding: + enabled: true diff --git a/config/test-6.yaml b/config/test-6.yaml index 169af973a..d74d3b052 100644 --- a/config/test-6.yaml +++ b/config/test-6.yaml @@ -18,6 +18,3 @@ storage: admin: email: 'admin6@example.com' - -transcoding: - enabled: true diff --git a/server/tests/api/index.js b/server/tests/api/index.js index 7ae18f674..cc86a3d3b 100644 --- a/server/tests/api/index.js +++ b/server/tests/api/index.js @@ -11,3 +11,4 @@ require('./video-blacklist') require('./multiple-pods') require('./requests') require('./friends-advanced') +require('./video-transcoder') diff --git a/server/tests/api/video-transcoder.js b/server/tests/api/video-transcoder.js new file mode 100644 index 000000000..3ff7b230a --- /dev/null +++ b/server/tests/api/video-transcoder.js @@ -0,0 +1,115 @@ +/* eslint-disable no-unused-expressions */ + +'use strict' + +const chai = require('chai') +const each = require('async/each') +const expect = chai.expect +const series = require('async/series') +const webtorrent = new (require('webtorrent'))() + +const loginUtils = require('../utils/login') +const serversUtils = require('../utils/servers') +const videosUtils = require('../utils/videos') + +describe('Test video blacklists', function () { + let servers = [] + + before(function (done) { + this.timeout(30000) + + series([ + // Run servers + function (next) { + serversUtils.flushAndRunMultipleServers(2, function (serversRun) { + servers = serversRun + next() + }) + }, + // Get the access tokens + function (next) { + each(servers, function (server, callbackEach) { + loginUtils.loginAndGetAccessToken(server, function (err, accessToken) { + if (err) return callbackEach(err) + + server.accessToken = accessToken + callbackEach() + }) + }, next) + } + ], done) + }) + + it('Should not transcode video on server 1', function (done) { + this.timeout(60000) + + const videoAttributes = { + name: 'my super name for pod 1', + description: 'my super description for pod 1', + fixture: 'video_short.webm' + } + videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes, function (err) { + if (err) throw err + + setTimeout(function () { + videosUtils.getVideosList(servers[0].url, function (err, res) { + if (err) throw err + + const video = res.body.data[0] + expect(video.magnetUri).to.match(/\.webm/) + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).match(/\.webm$/) + + done() + }) + }) + }, 30000) + }) + }) + + it('Should transcode video on server 2', function (done) { + this.timeout(60000) + + const videoAttributes = { + name: 'my super name for pod 2', + description: 'my super description for pod 2', + fixture: 'video_short.webm' + } + videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, function (err) { + if (err) throw err + + setTimeout(function () { + videosUtils.getVideosList(servers[1].url, function (err, res) { + if (err) throw err + + const video = res.body.data[0] + expect(video.magnetUri).to.match(/\.mp4/) + + webtorrent.add(video.magnetUri, function (torrent) { + expect(torrent.files).to.exist + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).match(/\.mp4$/) + + done() + }) + }) + }, 30000) + }) + }) + + after(function (done) { + servers.forEach(function (server) { + process.kill(-server.app.pid) + }) + + // Keep the logs if the test failed + if (this.ok) { + serversUtils.flushTests(done) + } else { + done() + } + }) +})