create-transcoding-job.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import * as chai from 'chai'
  4. import { VideoDetails } from '../../../shared/models/videos'
  5. import {
  6. doubleFollow,
  7. execCLI,
  8. flushAndRunMultipleServers,
  9. flushTests,
  10. getEnvCli,
  11. getVideo,
  12. getVideosList,
  13. killallServers,
  14. ServerInfo,
  15. setAccessTokensToServers,
  16. uploadVideo, wait
  17. } from '../../../shared/extra-utils'
  18. import { waitJobs } from '../../../shared/extra-utils/server/jobs'
  19. const expect = chai.expect
  20. describe('Test create transcoding jobs', function () {
  21. let servers: ServerInfo[] = []
  22. let video1UUID: string
  23. let video2UUID: string
  24. before(async function () {
  25. this.timeout(60000)
  26. // Run server 2 to have transcoding enabled
  27. servers = await flushAndRunMultipleServers(2)
  28. await setAccessTokensToServers(servers)
  29. await doubleFollow(servers[0], servers[1])
  30. // Upload two videos for our needs
  31. const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
  32. video1UUID = res1.body.video.uuid
  33. const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
  34. video2UUID = res2.body.video.uuid
  35. await waitJobs(servers)
  36. })
  37. it('Should have two video files on each server', async function () {
  38. this.timeout(30000)
  39. for (const server of servers) {
  40. const res = await getVideosList(server.url)
  41. const videos = res.body.data
  42. expect(videos).to.have.lengthOf(2)
  43. for (const video of videos) {
  44. const res2 = await getVideo(server.url, video.uuid)
  45. const videoDetail: VideoDetails = res2.body
  46. expect(videoDetail.files).to.have.lengthOf(1)
  47. }
  48. }
  49. })
  50. it('Should run a transcoding job on video 2', async function () {
  51. this.timeout(60000)
  52. const env = getEnvCli(servers[0])
  53. await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
  54. await waitJobs(servers)
  55. for (const server of servers) {
  56. const res = await getVideosList(server.url)
  57. const videos = res.body.data
  58. expect(videos).to.have.lengthOf(2)
  59. let infoHashes: { [ id: number ]: string }
  60. for (const video of videos) {
  61. const res2 = await getVideo(server.url, video.uuid)
  62. const videoDetail: VideoDetails = res2.body
  63. if (video.uuid === video2UUID) {
  64. expect(videoDetail.files).to.have.lengthOf(4)
  65. if (!infoHashes) {
  66. infoHashes = {}
  67. for (const file of videoDetail.files) {
  68. infoHashes[file.resolution.id.toString()] = file.magnetUri
  69. }
  70. } else {
  71. for (const resolution of Object.keys(infoHashes)) {
  72. const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
  73. expect(file.magnetUri).to.equal(infoHashes[resolution])
  74. }
  75. }
  76. } else {
  77. expect(videoDetail.files).to.have.lengthOf(1)
  78. }
  79. }
  80. }
  81. })
  82. it('Should run a transcoding job on video 1 with resolution', async function () {
  83. this.timeout(60000)
  84. const env = getEnvCli(servers[0])
  85. await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
  86. await waitJobs(servers)
  87. for (const server of servers) {
  88. const res = await getVideosList(server.url)
  89. const videos = res.body.data
  90. expect(videos).to.have.lengthOf(2)
  91. const res2 = await getVideo(server.url, video1UUID)
  92. const videoDetail: VideoDetails = res2.body
  93. expect(videoDetail.files).to.have.lengthOf(2)
  94. expect(videoDetail.files[0].resolution.id).to.equal(720)
  95. expect(videoDetail.files[1].resolution.id).to.equal(480)
  96. }
  97. })
  98. after(function () {
  99. killallServers(servers)
  100. })
  101. })