2018-05-30 03:49:40 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import { VideoDetails } from '../../../shared/models/videos'
|
|
|
|
import {
|
2018-06-13 03:06:50 -05:00
|
|
|
doubleFollow,
|
2018-05-30 03:49:40 -05:00
|
|
|
execCLI,
|
2018-06-13 03:06:50 -05:00
|
|
|
flushAndRunMultipleServers,
|
2018-05-30 03:49:40 -05:00
|
|
|
flushTests,
|
|
|
|
getEnvCli,
|
2018-06-13 03:06:50 -05:00
|
|
|
getVideo,
|
2018-05-30 03:49:40 -05:00
|
|
|
getVideosList,
|
|
|
|
killallServers,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2018-06-13 03:06:50 -05:00
|
|
|
uploadVideo, wait
|
2018-10-29 11:48:31 -05:00
|
|
|
} from '../../../shared/utils'
|
|
|
|
import { waitJobs } from '../../../shared/utils/server/jobs'
|
2018-06-13 03:06:50 -05:00
|
|
|
|
|
|
|
const expect = chai.expect
|
2018-05-30 03:49:40 -05:00
|
|
|
|
|
|
|
describe('Test create transcoding jobs', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
2018-06-15 11:27:35 -05:00
|
|
|
let video1UUID: string
|
2018-05-30 03:49:40 -05:00
|
|
|
let video2UUID: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
await flushTests()
|
|
|
|
|
|
|
|
// Run server 2 to have transcoding enabled
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
// Upload two videos for our needs
|
2018-06-15 11:27:35 -05:00
|
|
|
const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
|
|
|
|
video1UUID = res1.body.video.uuid
|
|
|
|
const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
|
|
|
|
video2UUID = res2.body.video.uuid
|
2018-05-30 03:49:40 -05:00
|
|
|
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2018-05-30 03:49:40 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should have two video files on each server', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
for (const video of videos) {
|
|
|
|
const res2 = await getVideo(server.url, video.uuid)
|
|
|
|
const videoDetail: VideoDetails = res2.body
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run a transcoding job on video 2', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
const env = getEnvCli(servers[0])
|
|
|
|
await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
|
|
|
|
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2018-05-30 03:49:40 -05:00
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
2018-05-30 04:11:51 -05:00
|
|
|
let infoHashes: { [ id: number ]: string }
|
|
|
|
|
2018-05-30 03:49:40 -05:00
|
|
|
for (const video of videos) {
|
|
|
|
const res2 = await getVideo(server.url, video.uuid)
|
|
|
|
const videoDetail: VideoDetails = res2.body
|
|
|
|
|
|
|
|
if (video.uuid === video2UUID) {
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(4)
|
2018-05-30 04:11:51 -05:00
|
|
|
|
|
|
|
if (!infoHashes) {
|
|
|
|
infoHashes = {}
|
|
|
|
|
|
|
|
for (const file of videoDetail.files) {
|
|
|
|
infoHashes[file.resolution.id.toString()] = file.magnetUri
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const resolution of Object.keys(infoHashes)) {
|
|
|
|
const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
|
|
|
|
expect(file.magnetUri).to.equal(infoHashes[resolution])
|
|
|
|
}
|
|
|
|
}
|
2018-05-30 03:49:40 -05:00
|
|
|
} else {
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-15 11:27:35 -05:00
|
|
|
it('Should run a transcoding job on video 1 with resolution', async function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
const env = getEnvCli(servers[0])
|
|
|
|
await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const res2 = await getVideo(server.url, video1UUID)
|
|
|
|
const videoDetail: VideoDetails = res2.body
|
|
|
|
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
expect(videoDetail.files[0].resolution.id).to.equal(720)
|
|
|
|
|
|
|
|
expect(videoDetail.files[1].resolution.id).to.equal(480)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-05-30 03:49:40 -05:00
|
|
|
after(async function () {
|
|
|
|
killallServers(servers)
|
|
|
|
})
|
|
|
|
})
|