X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fcli%2Fprune-storage.ts;h=2d4c02da74482aee2148e8a6f10f9591d00ccc2b;hb=efa3fef23ecf4e1c5289f8715de184c272ea49f7;hp=a4556312b36773b400551c3152eeb4d09e38c0d7;hpb=d23dd9fbfc4d26026352c10f81d2795ceaf2908a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index a4556312b..2d4c02da7 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -5,39 +5,38 @@ import * as chai from 'chai' import { createFile, readdir } from 'fs-extra' import { join } from 'path' import { buildUUID } from '@server/helpers/uuid' -import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, CLICommand, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, killallServers, makeGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, wait, waitJobs } from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect -async function countFiles (server: ServerInfo, directory: string) { - const files = await readdir(server.serversCommand.buildDirectory(directory)) +async function countFiles (server: PeerTubeServer, directory: string) { + const files = await readdir(server.servers.buildDirectory(directory)) return files.length } -async function assertNotExists (server: ServerInfo, directory: string, substring: string) { - const files = await readdir(server.serversCommand.buildDirectory(directory)) +async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) { + const files = await readdir(server.servers.buildDirectory(directory)) for (const f of files) { expect(f).to.not.contain(substring) } } -async function assertCountAreOkay (servers: ServerInfo[]) { +async function assertCountAreOkay (servers: PeerTubeServer[], videoServer2UUID: string) { for (const server of servers) { const videosCount = await countFiles(server, 'videos') expect(videosCount).to.equal(8) @@ -54,30 +53,41 @@ async function assertCountAreOkay (servers: ServerInfo[]) { const avatarsCount = await countFiles(server, 'avatars') expect(avatarsCount).to.equal(2) } + + // When we'll prune HLS directories too + // const hlsRootCount = await countFiles(servers[1], 'streaming-playlists/hls/') + // expect(hlsRootCount).to.equal(2) + + // const hlsCount = await countFiles(servers[1], 'streaming-playlists/hls/' + videoServer2UUID) + // expect(hlsCount).to.equal(10) } describe('Test prune storage scripts', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] const badNames: { [directory: string]: string[] } = {} + let videoServer2UUID: string + before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true } }) + servers = await createMultipleServers(2, { transcoding: { enabled: true } }) await setAccessTokensToServers(servers) await setDefaultVideoChannel(servers) for (const server of servers) { - await server.videosCommand.upload({ attributes: { name: 'video 1' } }) - await server.videosCommand.upload({ attributes: { name: 'video 2' } }) + await server.videos.upload({ attributes: { name: 'video 1' } }) - await server.usersCommand.updateMyAvatar({ fixture: 'avatar.png' }) + const { uuid } = await server.videos.upload({ attributes: { name: 'video 2' } }) + if (server.serverNumber === 2) videoServer2UUID = uuid - await server.playlistsCommand.create({ + await server.users.updateMyAvatar({ fixture: 'avatar.png' }) + + await server.playlists.create({ attributes: { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, - videoChannelId: server.videoChannel.id, + videoChannelId: server.store.channel.id, thumbnailfile: 'thumbnail.jpg' } }) @@ -87,20 +97,20 @@ describe('Test prune storage scripts', function () { // Lazy load the remote avatar { - const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port }) + const account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port }) await makeGetRequest({ url: servers[0].url, path: account.avatar.path, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) } { - const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port }) + const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port }) await makeGetRequest({ url: servers[1].url, path: account.avatar.path, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) } @@ -113,13 +123,13 @@ describe('Test prune storage scripts', function () { }) it('Should have the files on the disk', async function () { - await assertCountAreOkay(servers) + await assertCountAreOkay(servers, videoServer2UUID) }) it('Should create some dirty files', async function () { for (let i = 0; i < 2; i++) { { - const base = servers[0].serversCommand.buildDirectory('videos') + const base = servers[0].servers.buildDirectory('videos') const n1 = buildUUID() + '.mp4' const n2 = buildUUID() + '.webm' @@ -131,7 +141,7 @@ describe('Test prune storage scripts', function () { } { - const base = servers[0].serversCommand.buildDirectory('torrents') + const base = servers[0].servers.buildDirectory('torrents') const n1 = buildUUID() + '-240.torrent' const n2 = buildUUID() + '-480.torrent' @@ -143,7 +153,7 @@ describe('Test prune storage scripts', function () { } { - const base = servers[0].serversCommand.buildDirectory('thumbnails') + const base = servers[0].servers.buildDirectory('thumbnails') const n1 = buildUUID() + '.jpg' const n2 = buildUUID() + '.jpg' @@ -155,7 +165,7 @@ describe('Test prune storage scripts', function () { } { - const base = servers[0].serversCommand.buildDirectory('previews') + const base = servers[0].servers.buildDirectory('previews') const n1 = buildUUID() + '.jpg' const n2 = buildUUID() + '.jpg' @@ -167,7 +177,7 @@ describe('Test prune storage scripts', function () { } { - const base = servers[0].serversCommand.buildDirectory('avatars') + const base = servers[0].servers.buildDirectory('avatars') const n1 = buildUUID() + '.png' const n2 = buildUUID() + '.jpg' @@ -177,18 +187,40 @@ describe('Test prune storage scripts', function () { badNames['avatars'] = [ n1, n2 ] } + + // When we'll prune HLS directories too + // { + // const directory = join('streaming-playlists', 'hls') + // const base = servers[1].servers.buildDirectory(directory) + + // const n1 = buildUUID() + // await createFile(join(base, n1)) + // badNames[directory] = [ n1 ] + // } + + // { + // const directory = join('streaming-playlists', 'hls', videoServer2UUID) + // const base = servers[1].servers.buildDirectory(directory) + // const n1 = buildUUID() + '-240-fragmented-.mp4' + // const n2 = buildUUID() + '-master.m3u8' + + // await createFile(join(base, n1)) + // await createFile(join(base, n2)) + + // badNames[directory] = [ n1, n2 ] + // } } }) it('Should run prune storage', async function () { this.timeout(30000) - const env = servers[0].cliCommand.getEnv() + const env = servers[0].cli.getEnv() await CLICommand.exec(`echo y | ${env} npm run prune-storage`) }) it('Should have removed files', async function () { - await assertCountAreOkay(servers) + await assertCountAreOkay(servers, videoServer2UUID) for (const directory of Object.keys(badNames)) { for (const name of badNames[directory]) {