aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xscripts/clean/server/test.sh2
-rw-r--r--server/tests/real-world/populate-database.ts110
2 files changed, 111 insertions, 1 deletions
diff --git a/scripts/clean/server/test.sh b/scripts/clean/server/test.sh
index 753b8c67e..42651d3a8 100755
--- a/scripts/clean/server/test.sh
+++ b/scripts/clean/server/test.sh
@@ -3,7 +3,7 @@
3set -eu 3set -eu
4 4
5for i in $(seq 1 6); do 5for i in $(seq 1 6); do
6 dropdb "peertube_test$i" 6 dropdb --if-exists "peertube_test$i"
7 rm -rf "./test$i" 7 rm -rf "./test$i"
8 rm -f "./config/local-test.json" 8 rm -f "./config/local-test.json"
9 rm -f "./config/local-test-$i.json" 9 rm -f "./config/local-test-$i.json"
diff --git a/server/tests/real-world/populate-database.ts b/server/tests/real-world/populate-database.ts
new file mode 100644
index 000000000..5f93d09db
--- /dev/null
+++ b/server/tests/real-world/populate-database.ts
@@ -0,0 +1,110 @@
1import { VideoRateType } from '../../../shared'
2import {
3 addVideoChannel,
4 createUser,
5 flushTests,
6 getVideosList,
7 killallServers,
8 rateVideo,
9 runServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 uploadVideo
13} from '../utils'
14import * as Bluebird from 'bluebird'
15
16start()
17 .catch(err => console.error(err))
18
19// ----------------------------------------------------------------------------
20
21async function start () {
22 process.on('exit', async () => {
23 killallServers([ server ])
24 return
25 })
26 process.on('SIGINT', goodbye)
27 process.on('SIGTERM', goodbye)
28
29 await flushTests()
30
31 console.log('Flushed tests.')
32
33 const server = await runServer(6)
34 await setAccessTokensToServers([ server ])
35
36 console.log('Servers ran.')
37
38 // Forever
39 const fakeTab = Array.from(Array(1000000).keys())
40 await Bluebird.map(fakeTab, () => {
41 return Promise.all([
42 uploadCustom(server),
43 likeCustom(server),
44 dislikeCustom(server),
45 createUserCustom(server),
46 createCustomChannel(server)
47 ]).catch(err => console.error(err))
48 }, { concurrency: 5 })
49}
50
51function getRandomInt (min, max) {
52 return Math.floor(Math.random() * (max - min)) + min
53}
54
55function createCustomChannel (server: ServerInfo) {
56 const videoChannel = {
57 displayName: Date.now().toString(),
58 description: Date.now().toString()
59 }
60
61 return addVideoChannel(server.url, server.accessToken, videoChannel)
62}
63
64function createUserCustom (server: ServerInfo) {
65 const username = Date.now().toString() + getRandomInt(0, 100000)
66 console.log('Creating user %s.', username)
67
68 return createUser(server.url, server.accessToken, username, 'coucou')
69}
70
71function uploadCustom (server: ServerInfo) {
72 console.log('Uploading video.')
73
74 const videoAttributes = {
75 name: Date.now() + ' name',
76 category: 4,
77 nsfw: false,
78 licence: 2,
79 language: 'en',
80 description: Date.now() + ' description',
81 tags: [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ],
82 fixture: 'video_short.mp4'
83 }
84
85 return uploadVideo(server.url, server.accessToken, videoAttributes)
86}
87
88function likeCustom (server: ServerInfo) {
89 return rateCustom(server, 'like')
90}
91
92function dislikeCustom (server: ServerInfo) {
93 return rateCustom(server, 'dislike')
94}
95
96async function rateCustom (server: ServerInfo, rating: VideoRateType) {
97 const res = await getVideosList(server.url)
98
99 const videos = res.body.data
100 if (videos.length === 0) return undefined
101
102 const videoToRate = videos[getRandomInt(0, videos.length)]
103
104 console.log('Rating (%s) video.', rating)
105 return rateVideo(server.url, server.accessToken, videoToRate.id, rating)
106}
107
108function goodbye () {
109 return process.exit(-1)
110}