diff options
Diffstat (limited to 'server/tests/real-world/populate-database.ts')
-rw-r--r-- | server/tests/real-world/populate-database.ts | 122 |
1 files changed, 0 insertions, 122 deletions
diff --git a/server/tests/real-world/populate-database.ts b/server/tests/real-world/populate-database.ts deleted file mode 100644 index b1c1688e7..000000000 --- a/server/tests/real-world/populate-database.ts +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | import { VideoRateType } from '../../../shared' | ||
2 | import { | ||
3 | addVideoChannel, | ||
4 | createUser, | ||
5 | flushTests, | ||
6 | getVideosList, | ||
7 | killallServers, | ||
8 | rateVideo, | ||
9 | flushAndRunServer, | ||
10 | ServerInfo, | ||
11 | setAccessTokensToServers, | ||
12 | uploadVideo | ||
13 | } from '../../../shared/extra-utils' | ||
14 | import * as Bluebird from 'bluebird' | ||
15 | |||
16 | start() | ||
17 | .catch(err => console.error(err)) | ||
18 | |||
19 | // ---------------------------------------------------------------------------- | ||
20 | |||
21 | async function start () { | ||
22 | |||
23 | console.log('Flushed tests.') | ||
24 | |||
25 | const server = await flushAndRunServer(6) | ||
26 | |||
27 | process.on('exit', async () => { | ||
28 | killallServers([ server ]) | ||
29 | return | ||
30 | }) | ||
31 | process.on('SIGINT', goodbye) | ||
32 | process.on('SIGTERM', goodbye) | ||
33 | |||
34 | await setAccessTokensToServers([ server ]) | ||
35 | |||
36 | console.log('Servers ran.') | ||
37 | |||
38 | // Forever | ||
39 | const fakeTab = Array.from(Array(1000000).keys()) | ||
40 | const funs = [ | ||
41 | uploadCustom | ||
42 | // uploadCustom, | ||
43 | // uploadCustom, | ||
44 | // uploadCustom, | ||
45 | // likeCustom, | ||
46 | // createUserCustom, | ||
47 | // createCustomChannel | ||
48 | ] | ||
49 | const promises = [] | ||
50 | |||
51 | for (const fun of funs) { | ||
52 | promises.push( | ||
53 | Bluebird.map(fakeTab, () => { | ||
54 | return fun(server).catch(err => console.error(err)) | ||
55 | }, { concurrency: 3 }) | ||
56 | ) | ||
57 | } | ||
58 | |||
59 | await Promise.all(promises) | ||
60 | } | ||
61 | |||
62 | function getRandomInt (min, max) { | ||
63 | return Math.floor(Math.random() * (max - min)) + min | ||
64 | } | ||
65 | |||
66 | function createCustomChannel (server: ServerInfo) { | ||
67 | const videoChannel = { | ||
68 | name: Date.now().toString(), | ||
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({ url: server.url, accessToken: server.accessToken, username: username, password: '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 | } | ||