aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/transcoding/update-while-transcoding.ts
blob: 8e32ea069d3eaad7e2adde21b0548576e62d5deb (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
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import { completeCheckHlsPlaylist } from '@server/tests/shared'
import { areMockObjectStorageTestsDisabled, wait } from '@shared/core-utils'
import { VideoPrivacy } from '@shared/models'
import {
  cleanupTests,
  createMultipleServers,
  doubleFollow,
  ObjectStorageCommand,
  PeerTubeServer,
  setAccessTokensToServers,
  waitJobs
} from '@shared/server-commands'

describe('Test update video privacy while transcoding', function () {
  let servers: PeerTubeServer[] = []

  const videoUUIDs: string[] = []

  function runTestSuite (hlsOnly: boolean, objectStorageBaseUrl?: string) {

    it('Should not have an error while quickly updating a private video to public after upload #1', async function () {
      this.timeout(360_000)

      const attributes = {
        name: 'quick update',
        privacy: VideoPrivacy.PRIVATE
      }

      const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: false })
      await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
      videoUUIDs.push(uuid)

      await waitJobs(servers)

      await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
    })

    it('Should not have an error while quickly updating a private video to public after upload #2', async function () {

      {
        const attributes = {
          name: 'quick update 2',
          privacy: VideoPrivacy.PRIVATE
        }

        const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: true })
        await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
        videoUUIDs.push(uuid)

        await waitJobs(servers)

        await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
      }
    })

    it('Should not have an error while quickly updating a private video to public after upload #3', async function () {
      const attributes = {
        name: 'quick update 3',
        privacy: VideoPrivacy.PRIVATE
      }

      const { uuid } = await servers[0].videos.upload({ attributes, waitTorrentGeneration: true })
      await wait(1000)
      await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } })
      videoUUIDs.push(uuid)

      await waitJobs(servers)

      await completeCheckHlsPlaylist({ servers, videoUUID: uuid, hlsOnly, objectStorageBaseUrl })
    })
  }

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

    const configOverride = {
      transcoding: {
        enabled: true,
        allow_audio_files: true,
        hls: {
          enabled: true
        }
      }
    }
    servers = await createMultipleServers(2, configOverride)

    // Get the access tokens
    await setAccessTokensToServers(servers)

    // Server 1 and server 2 follow each other
    await doubleFollow(servers[0], servers[1])
  })

  describe('With WebTorrent & HLS enabled', function () {
    runTestSuite(false)
  })

  describe('With only HLS enabled', function () {

    before(async function () {
      await servers[0].config.updateCustomSubConfig({
        newConfig: {
          transcoding: {
            enabled: true,
            allowAudioFiles: true,
            resolutions: {
              '144p': false,
              '240p': true,
              '360p': true,
              '480p': true,
              '720p': true,
              '1080p': true,
              '1440p': true,
              '2160p': true
            },
            hls: {
              enabled: true
            },
            webtorrent: {
              enabled: false
            }
          }
        }
      })
    })

    runTestSuite(true)
  })

  describe('With object storage enabled', function () {
    if (areMockObjectStorageTestsDisabled()) return

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

      const configOverride = ObjectStorageCommand.getDefaultMockConfig()
      await ObjectStorageCommand.prepareDefaultMockBuckets()

      await servers[0].kill()
      await servers[0].run(configOverride)
    })

    runTestSuite(true, ObjectStorageCommand.getMockPlaylistBaseUrl())
  })

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