create-transcoding-job.ts 3.7 KB

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