aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-create-transcoding.ts
blob: dcdbd9c6ed74caa8ce519c9f28b1e75836a53158 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import { expectStartWith } from '@server/tests/shared'
import { areObjectStorageTestsDisabled } from '@shared/core-utils'
import { HttpStatusCode, VideoDetails } from '@shared/models'
import {
  cleanupTests,
  createMultipleServers,
  doubleFollow,
  expectNoFailedTranscodingJob,
  makeRawRequest,
  ObjectStorageCommand,
  PeerTubeServer,
  setAccessTokensToServers,
  waitJobs
} from '@shared/server-commands'

const expect = chai.expect

async function checkFilesInObjectStorage (video: VideoDetails) {
  for (const file of video.files) {
    expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
    await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
  }

  const streamingPlaylistFiles = video.streamingPlaylists.length === 0
    ? []
    : video.streamingPlaylists[0].files

  for (const file of streamingPlaylistFiles) {
    expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
    await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
  }
}

function runTests (objectStorage: boolean) {
  let servers: PeerTubeServer[] = []
  let videoUUID: string
  let publishedAt: string

  before(async function () {
    this.timeout(120000)

    const config = objectStorage
      ? ObjectStorageCommand.getDefaultConfig()
      : {}

    // Run server 2 to have transcoding enabled
    servers = await createMultipleServers(2, config)
    await setAccessTokensToServers(servers)

    await servers[0].config.disableTranscoding()

    await doubleFollow(servers[0], servers[1])

    if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()

    const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
    videoUUID = shortUUID

    await waitJobs(servers)

    const video = await servers[0].videos.get({ id: videoUUID })
    publishedAt = video.publishedAt as string

    await servers[0].config.enableTranscoding()
  })

  it('Should generate HLS', async function () {
    this.timeout(60000)

    await servers[0].videos.runTranscoding({
      videoId: videoUUID,
      transcodingType: 'hls'
    })

    await waitJobs(servers)
    await expectNoFailedTranscodingJob(servers[0])

    for (const server of servers) {
      const videoDetails = await server.videos.get({ id: videoUUID })

      expect(videoDetails.files).to.have.lengthOf(1)
      expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
      expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)

      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
    }
  })

  it('Should generate WebTorrent', async function () {
    this.timeout(60000)

    await servers[0].videos.runTranscoding({
      videoId: videoUUID,
      transcodingType: 'webtorrent'
    })

    await waitJobs(servers)

    for (const server of servers) {
      const videoDetails = await server.videos.get({ id: videoUUID })

      expect(videoDetails.files).to.have.lengthOf(5)
      expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
      expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)

      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
    }
  })

  it('Should generate WebTorrent from HLS only video', async function () {
    this.timeout(60000)

    await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
    await waitJobs(servers)

    await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
    await waitJobs(servers)

    for (const server of servers) {
      const videoDetails = await server.videos.get({ id: videoUUID })

      expect(videoDetails.files).to.have.lengthOf(5)
      expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
      expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)

      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
    }
  })

  it('Should only generate WebTorrent', async function () {
    this.timeout(60000)

    await servers[0].videos.removeHLSFiles({ videoId: videoUUID })
    await waitJobs(servers)

    await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
    await waitJobs(servers)

    for (const server of servers) {
      const videoDetails = await server.videos.get({ id: videoUUID })

      expect(videoDetails.files).to.have.lengthOf(5)
      expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)

      if (objectStorage) await checkFilesInObjectStorage(videoDetails)
    }
  })

  it('Should not have updated published at attributes', async function () {
    const video = await servers[0].videos.get({ id: videoUUID })

    expect(video.publishedAt).to.equal(publishedAt)
  })

  after(async function () {
    await cleanupTests(servers)
  })
}

describe('Test create transcoding jobs from API', function () {

  describe('On filesystem', function () {
    runTests(false)
  })

  describe('On object storage', function () {
    if (areObjectStorageTestsDisabled()) return

    runTests(true)
  })
})