refresher.ts 4.8 KB

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