create-move-video-storage-job.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
  3. import { HttpStatusCode, VideoDetails } from '@shared/models'
  4. import {
  5. cleanupTests,
  6. createMultipleServers,
  7. doubleFollow,
  8. makeRawRequest,
  9. ObjectStorageCommand,
  10. PeerTubeServer,
  11. setAccessTokensToServers,
  12. waitJobs
  13. } from '@shared/server-commands'
  14. import { expectStartWith } from '../shared'
  15. async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) {
  16. for (const file of video.files) {
  17. const start = inObjectStorage
  18. ? ObjectStorageCommand.getMockWebTorrentBaseUrl()
  19. : origin.url
  20. expectStartWith(file.fileUrl, start)
  21. await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
  22. }
  23. const start = inObjectStorage
  24. ? ObjectStorageCommand.getMockPlaylistBaseUrl()
  25. : origin.url
  26. const hls = video.streamingPlaylists[0]
  27. expectStartWith(hls.playlistUrl, start)
  28. expectStartWith(hls.segmentsSha256Url, start)
  29. for (const file of hls.files) {
  30. expectStartWith(file.fileUrl, start)
  31. await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
  32. }
  33. }
  34. describe('Test create move video storage job', function () {
  35. if (areMockObjectStorageTestsDisabled()) return
  36. let servers: PeerTubeServer[] = []
  37. const uuids: string[] = []
  38. before(async function () {
  39. this.timeout(360000)
  40. // Run server 2 to have transcoding enabled
  41. servers = await createMultipleServers(2)
  42. await setAccessTokensToServers(servers)
  43. await doubleFollow(servers[0], servers[1])
  44. await ObjectStorageCommand.prepareDefaultMockBuckets()
  45. await servers[0].config.enableTranscoding()
  46. for (let i = 0; i < 3; i++) {
  47. const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
  48. uuids.push(uuid)
  49. }
  50. await waitJobs(servers)
  51. await servers[0].kill()
  52. await servers[0].run(ObjectStorageCommand.getDefaultMockConfig())
  53. })
  54. it('Should move only one file', async function () {
  55. this.timeout(120000)
  56. const command = `npm run create-move-video-storage-job -- --to-object-storage -v ${uuids[1]}`
  57. await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
  58. await waitJobs(servers)
  59. for (const server of servers) {
  60. const video = await server.videos.get({ id: uuids[1] })
  61. await checkFiles(servers[0], video, true)
  62. for (const id of [ uuids[0], uuids[2] ]) {
  63. const video = await server.videos.get({ id })
  64. await checkFiles(servers[0], video, false)
  65. }
  66. }
  67. })
  68. it('Should move all files', async function () {
  69. this.timeout(120000)
  70. const command = `npm run create-move-video-storage-job -- --to-object-storage --all-videos`
  71. await servers[0].cli.execWithEnv(command, ObjectStorageCommand.getDefaultMockConfig())
  72. await waitJobs(servers)
  73. for (const server of servers) {
  74. for (const id of [ uuids[0], uuids[2] ]) {
  75. const video = await server.videos.get({ id })
  76. await checkFiles(servers[0], video, true)
  77. }
  78. }
  79. })
  80. after(async function () {
  81. await cleanupTests(servers)
  82. })
  83. })