refresher.ts 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* tslint:disable:no-unused-expression */
  2. import 'mocha'
  3. import {
  4. cleanupTests, closeAllSequelize,
  5. createVideoPlaylist,
  6. doubleFollow,
  7. flushAndRunMultipleServers,
  8. generateUserAccessToken,
  9. getVideo,
  10. getVideoPlaylist,
  11. killallServers,
  12. reRunServer,
  13. ServerInfo,
  14. setAccessTokensToServers,
  15. setActorField,
  16. setDefaultVideoChannel,
  17. setPlaylistField,
  18. setVideoField,
  19. uploadVideo,
  20. uploadVideoAndGetId,
  21. wait,
  22. waitJobs
  23. } from '../../../../shared/extra-utils'
  24. import { getAccount } from '../../../../shared/extra-utils/users/accounts'
  25. import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
  26. describe('Test AP refresher', function () {
  27. let servers: ServerInfo[] = []
  28. let videoUUID1: string
  29. let videoUUID2: string
  30. let videoUUID3: string
  31. let playlistUUID1: string
  32. let playlistUUID2: string
  33. before(async function () {
  34. this.timeout(60000)
  35. servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: false } })
  36. // Get the access tokens
  37. await setAccessTokensToServers(servers)
  38. await setDefaultVideoChannel(servers)
  39. {
  40. videoUUID1 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video1' })).uuid
  41. videoUUID2 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video2' })).uuid
  42. videoUUID3 = (await uploadVideoAndGetId({ server: servers[ 1 ], videoName: 'video3' })).uuid
  43. }
  44. {
  45. const a1 = await generateUserAccessToken(servers[ 1 ], 'user1')
  46. await uploadVideo(servers[ 1 ].url, a1, { name: 'video4' })
  47. const a2 = await generateUserAccessToken(servers[ 1 ], 'user2')
  48. await uploadVideo(servers[ 1 ].url, a2, { name: 'video5' })
  49. }
  50. {
  51. const playlistAttrs = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
  52. const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
  53. playlistUUID1 = res.body.videoPlaylist.uuid
  54. }
  55. {
  56. const playlistAttrs = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[ 1 ].videoChannel.id }
  57. const res = await createVideoPlaylist({ url: servers[ 1 ].url, token: servers[ 1 ].accessToken, playlistAttrs })
  58. playlistUUID2 = res.body.videoPlaylist.uuid
  59. }
  60. await doubleFollow(servers[ 0 ], servers[ 1 ])
  61. })
  62. describe('Videos refresher', function () {
  63. it('Should remove a deleted remote video', async function () {
  64. this.timeout(60000)
  65. await wait(10000)
  66. // Change UUID so the remote server returns a 404
  67. await setVideoField(servers[ 1 ].internalServerNumber, videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
  68. await getVideo(servers[ 0 ].url, videoUUID1)
  69. await getVideo(servers[ 0 ].url, videoUUID2)
  70. await waitJobs(servers)
  71. await getVideo(servers[ 0 ].url, videoUUID1, 404)
  72. await getVideo(servers[ 0 ].url, videoUUID2, 200)
  73. })
  74. it('Should not update a remote video if the remote instance is down', async function () {
  75. this.timeout(70000)
  76. killallServers([ servers[ 1 ] ])
  77. await setVideoField(servers[ 1 ].internalServerNumber, videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
  78. // Video will need a refresh
  79. await wait(10000)
  80. await getVideo(servers[ 0 ].url, videoUUID3)
  81. // The refresh should fail
  82. await waitJobs([ servers[ 0 ] ])
  83. await reRunServer(servers[ 1 ])
  84. await getVideo(servers[ 0 ].url, videoUUID3, 200)
  85. })
  86. })
  87. describe('Actors refresher', function () {
  88. it('Should remove a deleted actor', async function () {
  89. this.timeout(60000)
  90. await wait(10000)
  91. // Change actor name so the remote server returns a 404
  92. const to = 'http://localhost:' + servers[ 1 ].port + '/accounts/user2'
  93. await setActorField(servers[ 1 ].internalServerNumber, to, 'preferredUsername', 'toto')
  94. await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port)
  95. await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port)
  96. await waitJobs(servers)
  97. await getAccount(servers[ 0 ].url, 'user1@localhost:' + servers[ 1 ].port, 200)
  98. await getAccount(servers[ 0 ].url, 'user2@localhost:' + servers[ 1 ].port, 404)
  99. })
  100. })
  101. describe('Playlist refresher', function () {
  102. it('Should remove a deleted playlist', async function () {
  103. this.timeout(60000)
  104. await wait(10000)
  105. // Change UUID so the remote server returns a 404
  106. await setPlaylistField(servers[ 1 ].internalServerNumber, playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
  107. await getVideoPlaylist(servers[ 0 ].url, playlistUUID1)
  108. await getVideoPlaylist(servers[ 0 ].url, playlistUUID2)
  109. await waitJobs(servers)
  110. await getVideoPlaylist(servers[ 0 ].url, playlistUUID1, 200)
  111. await getVideoPlaylist(servers[ 0 ].url, playlistUUID2, 404)
  112. })
  113. })
  114. after(async function () {
  115. this.timeout(10000)
  116. await cleanupTests(servers)
  117. await closeAllSequelize(servers)
  118. })
  119. })