aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/follows.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-17 11:35:10 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commitafffe98839db7ccbfa9fb8b7d1413b97900fdc73 (patch)
treef0b3cbe58f73e81a5ba4bb31dabd9691994cf2ca /server/tests/utils/follows.ts
parent1b3989b0961d22a5a45ad16239e3c3f58f66180c (diff)
downloadPeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.tar.gz
PeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.tar.zst
PeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.zip
Speed up activity pub http requests
Diffstat (limited to 'server/tests/utils/follows.ts')
-rw-r--r--server/tests/utils/follows.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/server/tests/utils/follows.ts b/server/tests/utils/follows.ts
index 9ad1ca7f4..b454fe2f8 100644
--- a/server/tests/utils/follows.ts
+++ b/server/tests/utils/follows.ts
@@ -1,9 +1,9 @@
1import * as request from 'supertest' 1import * as request from 'supertest'
2
3import { wait } from './miscs' 2import { wait } from './miscs'
3import { ServerInfo } from './servers'
4 4
5function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) { 5function getFollowersListPaginationAndSort (url: string, start: number, count: number, sort: string) {
6 const path = '/api/v1/servers/followers' 6 const path = '/api/v1/server/followers'
7 7
8 return request(url) 8 return request(url)
9 .get(path) 9 .get(path)
@@ -16,7 +16,7 @@ function getFollowersListPaginationAndSort (url: string, start: number, count: n
16} 16}
17 17
18function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) { 18function getFollowingListPaginationAndSort (url: string, start: number, count: number, sort: string) {
19 const path = '/api/v1/servers/following' 19 const path = '/api/v1/server/following'
20 20
21 return request(url) 21 return request(url)
22 .get(path) 22 .get(path)
@@ -29,25 +29,36 @@ function getFollowingListPaginationAndSort (url: string, start: number, count: n
29} 29}
30 30
31async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) { 31async function follow (follower: string, following: string[], accessToken: string, expectedStatus = 204) {
32 const path = '/api/v1/servers/follow' 32 const path = '/api/v1/server/follow'
33 33
34 const followingHosts = following.map(f => f.replace(/^http:\/\//, ''))
34 const res = await request(follower) 35 const res = await request(follower)
35 .post(path) 36 .post(path)
36 .set('Accept', 'application/json') 37 .set('Accept', 'application/json')
37 .set('Authorization', 'Bearer ' + accessToken) 38 .set('Authorization', 'Bearer ' + accessToken)
38 .send({ 'hosts': following }) 39 .send({ 'hosts': followingHosts })
39 .expect(expectedStatus) 40 .expect(expectedStatus)
40 41
41 // Wait request propagation 42 // Wait request propagation
42 await wait(1000) 43 await wait(20000)
43 44
44 return res 45 return res
45} 46}
46 47
48async function doubleFollow (server1: ServerInfo, server2: ServerInfo) {
49 await Promise.all([
50 follow(server1.url, [ server2.url ], server1.accessToken),
51 follow(server2.url, [ server1.url ], server2.accessToken)
52 ])
53
54 return true
55}
56
47// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
48 58
49export { 59export {
50 getFollowersListPaginationAndSort, 60 getFollowersListPaginationAndSort,
51 getFollowingListPaginationAndSort, 61 getFollowingListPaginationAndSort,
52 follow 62 follow,
63 doubleFollow
53} 64}