aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/server/handle-down.ts147
1 files changed, 147 insertions, 0 deletions
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
new file mode 100644
index 000000000..da134c09f
--- /dev/null
+++ b/server/tests/api/server/handle-down.ts
@@ -0,0 +1,147 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos'
6import { completeVideoCheck, runServer, viewVideo } from '../../utils'
7
8import {
9 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
10 wait
11} from '../../utils/index'
12import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
13import { getJobsListPaginationAndSort } from '../../utils/server/jobs'
14
15const expect = chai.expect
16
17describe('Test handle downs', function () {
18 let servers: ServerInfo[] = []
19
20 const videoAttributes = {
21 name: 'my super name for server 1',
22 category: 5,
23 licence: 4,
24 language: 9,
25 nsfw: true,
26 description: 'my super description for server 1',
27 tags: [ 'tag1p1', 'tag2p1' ],
28 fixture: 'video_short1.webm'
29 }
30
31 const checkAttributes = {
32 name: 'my super name for server 1',
33 category: 5,
34 licence: 4,
35 language: 9,
36 nsfw: true,
37 description: 'my super description for server 1',
38 host: 'localhost:9001',
39 account: 'root',
40 isLocal: false,
41 duration: 10,
42 tags: [ 'tag1p1', 'tag2p1' ],
43 privacy: VideoPrivacy.PUBLIC,
44 commentsEnabled: true,
45 channel: {
46 name: 'Default root channel',
47 description: '',
48 isLocal: false
49 },
50 fixture: 'video_short1.webm',
51 files: [
52 {
53 resolution: 720,
54 size: 572456
55 }
56 ]
57 }
58
59 before(async function () {
60 this.timeout(20000)
61
62 servers = await flushAndRunMultipleServers(2)
63
64 // Get the access tokens
65 await setAccessTokensToServers(servers)
66 })
67
68 it('Should remove followers that are often down', async function () {
69 this.timeout(60000)
70
71 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
72
73 await wait(5000)
74
75 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
76
77 await wait(5000)
78
79 for (const server of servers) {
80 const res = await getVideosList(server.url)
81 expect(res.body.data).to.be.an('array')
82 expect(res.body.data).to.have.lengthOf(1)
83 }
84
85 // Kill server 1
86 killallServers([ servers[1] ])
87
88 // Remove server 2 follower
89 for (let i = 0; i < 10; i++) {
90 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
91 }
92
93 await wait(10000)
94
95 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
96 expect(res.body.data).to.be.an('array')
97 expect(res.body.data).to.have.lengthOf(0)
98 })
99
100 it('Should not have pending/processing jobs anymore', async function () {
101 const res = await getJobsListPaginationAndSort(servers[0].url, servers[0].accessToken, 0, 50, '-createdAt')
102 const jobs = res.body.data
103
104 for (const job of jobs) {
105 expect(job.state).not.to.equal('pending')
106 expect(job.state).not.to.equal('processing')
107 }
108 })
109
110 it('Should follow server 1', async function () {
111 servers[1] = await runServer(2)
112
113 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
114
115 await wait(5000)
116
117 const res = await getFollowersListPaginationAndSort(servers[0].url, 0, 1, 'createdAt')
118 expect(res.body.data).to.be.an('array')
119 expect(res.body.data).to.have.lengthOf(1)
120 })
121
122 it('Should send a view to server 2, and automatically fetch the video', async function () {
123 const resVideo = await getVideosList(servers[0].url)
124 const videoServer1 = resVideo.body.data[0]
125
126 await viewVideo(servers[0].url, videoServer1.uuid)
127
128 await wait(5000)
129
130 const res = await getVideosList(servers[1].url)
131 const videoServer2 = res.body.data.find(v => v.url === videoServer1.url)
132
133 expect(videoServer2).not.to.be.undefined
134
135 await completeVideoCheck(servers[1].url, videoServer2, checkAttributes)
136
137 })
138
139 after(async function () {
140 killallServers(servers)
141
142 // Keep the logs if the test failed
143 if (this['ok']) {
144 await flushTests()
145 }
146 })
147})