]>
Commit | Line | Data |
---|---|---|
b5443104 C |
1 | import { VideoRateType } from '../../../shared' |
2 | import { | |
3 | addVideoChannel, | |
4 | createUser, | |
5 | flushTests, | |
6 | getVideosList, | |
7 | killallServers, | |
8 | rateVideo, | |
9 | runServer, | |
10 | ServerInfo, | |
11 | setAccessTokensToServers, | |
12 | uploadVideo | |
13 | } from '../utils' | |
14 | import * as Bluebird from 'bluebird' | |
15 | ||
16 | start() | |
17 | .catch(err => console.error(err)) | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | ||
21 | async function start () { | |
e032aec9 C |
22 | await flushTests() |
23 | ||
24 | console.log('Flushed tests.') | |
25 | ||
26 | const server = await runServer(6) | |
27 | ||
b5443104 C |
28 | process.on('exit', async () => { |
29 | killallServers([ server ]) | |
30 | return | |
31 | }) | |
32 | process.on('SIGINT', goodbye) | |
33 | process.on('SIGTERM', goodbye) | |
34 | ||
b5443104 C |
35 | await setAccessTokensToServers([ server ]) |
36 | ||
37 | console.log('Servers ran.') | |
38 | ||
39 | // Forever | |
40 | const fakeTab = Array.from(Array(1000000).keys()) | |
7279b455 C |
41 | const funs = [ |
42 | uploadCustom | |
43 | // uploadCustom, | |
44 | // uploadCustom, | |
45 | // uploadCustom, | |
46 | // likeCustom, | |
47 | // createUserCustom, | |
48 | // createCustomChannel | |
49 | ] | |
50 | const promises = [] | |
51 | ||
52 | for (const fun of funs) { | |
53 | promises.push( | |
54 | Bluebird.map(fakeTab, () => { | |
55 | return fun(server).catch(err => console.error(err)) | |
56 | }, { concurrency: 3 }) | |
57 | ) | |
58 | } | |
59 | ||
60 | await Promise.all(promises) | |
b5443104 C |
61 | } |
62 | ||
63 | function getRandomInt (min, max) { | |
64 | return Math.floor(Math.random() * (max - min)) + min | |
65 | } | |
66 | ||
67 | function createCustomChannel (server: ServerInfo) { | |
68 | const videoChannel = { | |
69 | displayName: Date.now().toString(), | |
70 | description: Date.now().toString() | |
71 | } | |
72 | ||
73 | return addVideoChannel(server.url, server.accessToken, videoChannel) | |
74 | } | |
75 | ||
76 | function createUserCustom (server: ServerInfo) { | |
77 | const username = Date.now().toString() + getRandomInt(0, 100000) | |
78 | console.log('Creating user %s.', username) | |
79 | ||
80 | return createUser(server.url, server.accessToken, username, 'coucou') | |
81 | } | |
82 | ||
83 | function uploadCustom (server: ServerInfo) { | |
84 | console.log('Uploading video.') | |
85 | ||
86 | const videoAttributes = { | |
87 | name: Date.now() + ' name', | |
88 | category: 4, | |
89 | nsfw: false, | |
90 | licence: 2, | |
91 | language: 'en', | |
92 | description: Date.now() + ' description', | |
93 | tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ], | |
94 | fixture: 'video_short.mp4' | |
95 | } | |
96 | ||
97 | return uploadVideo(server.url, server.accessToken, videoAttributes) | |
98 | } | |
99 | ||
100 | function likeCustom (server: ServerInfo) { | |
101 | return rateCustom(server, 'like') | |
102 | } | |
103 | ||
104 | function dislikeCustom (server: ServerInfo) { | |
105 | return rateCustom(server, 'dislike') | |
106 | } | |
107 | ||
108 | async function rateCustom (server: ServerInfo, rating: VideoRateType) { | |
109 | const res = await getVideosList(server.url) | |
110 | ||
111 | const videos = res.body.data | |
112 | if (videos.length === 0) return undefined | |
113 | ||
114 | const videoToRate = videos[getRandomInt(0, videos.length)] | |
115 | ||
116 | console.log('Rating (%s) video.', rating) | |
117 | return rateVideo(server.url, server.accessToken, videoToRate.id, rating) | |
118 | } | |
119 | ||
120 | function goodbye () { | |
121 | return process.exit(-1) | |
122 | } |