refresher.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
  2. import { wait } from '@shared/core-utils'
  3. import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
  4. import {
  5. cleanupTests,
  6. createMultipleServers,
  7. doubleFollow,
  8. killallServers,
  9. PeerTubeServer,
  10. setAccessTokensToServers,
  11. setDefaultVideoChannel,
  12. waitJobs
  13. } from '@shared/server-commands'
  14. describe('Test AP refresher', function () {
  15. let servers: PeerTubeServer[] = []
  16. let videoUUID1: string
  17. let videoUUID2: string
  18. let videoUUID3: string
  19. let playlistUUID1: string
  20. let playlistUUID2: string
  21. before(async function () {
  22. this.timeout(60000)
  23. servers = await createMultipleServers(2)
  24. // Get the access tokens
  25. await setAccessTokensToServers(servers)
  26. await setDefaultVideoChannel(servers)
  27. for (const server of servers) {
  28. await server.config.disableTranscoding()
  29. }
  30. {
  31. videoUUID1 = (await servers[1].videos.quickUpload({ name: 'video1' })).uuid
  32. videoUUID2 = (await servers[1].videos.quickUpload({ name: 'video2' })).uuid
  33. videoUUID3 = (await servers[1].videos.quickUpload({ name: 'video3' })).uuid
  34. }
  35. {
  36. const token1 = await servers[1].users.generateUserAndToken('user1')
  37. await servers[1].videos.upload({ token: token1, attributes: { name: 'video4' } })
  38. const token2 = await servers[1].users.generateUserAndToken('user2')
  39. await servers[1].videos.upload({ token: token2, attributes: { name: 'video5' } })
  40. }
  41. {
  42. const attributes = { displayName: 'playlist1', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
  43. const created = await servers[1].playlists.create({ attributes })
  44. playlistUUID1 = created.uuid
  45. }
  46. {
  47. const attributes = { displayName: 'playlist2', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[1].store.channel.id }
  48. const created = await servers[1].playlists.create({ attributes })
  49. playlistUUID2 = created.uuid
  50. }
  51. await doubleFollow(servers[0], servers[1])
  52. })
  53. describe('Videos refresher', function () {
  54. it('Should remove a deleted remote video', async function () {
  55. this.timeout(60000)
  56. await wait(10000)
  57. // Change UUID so the remote server returns a 404
  58. await servers[1].sql.setVideoField(videoUUID1, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174f')
  59. await servers[0].videos.get({ id: videoUUID1 })
  60. await servers[0].videos.get({ id: videoUUID2 })
  61. await waitJobs(servers)
  62. await servers[0].videos.get({ id: videoUUID1, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
  63. await servers[0].videos.get({ id: videoUUID2 })
  64. })
  65. it('Should not update a remote video if the remote instance is down', async function () {
  66. this.timeout(70000)
  67. await killallServers([ servers[1] ])
  68. await servers[1].sql.setVideoField(videoUUID3, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b174e')
  69. // Video will need a refresh
  70. await wait(10000)
  71. await servers[0].videos.get({ id: videoUUID3 })
  72. // The refresh should fail
  73. await waitJobs([ servers[0] ])
  74. await servers[1].run()
  75. await servers[0].videos.get({ id: videoUUID3 })
  76. })
  77. })
  78. describe('Actors refresher', function () {
  79. it('Should remove a deleted actor', async function () {
  80. this.timeout(60000)
  81. const command = servers[0].accounts
  82. await wait(10000)
  83. // Change actor name so the remote server returns a 404
  84. const to = servers[1].url + '/accounts/user2'
  85. await servers[1].sql.setActorField(to, 'preferredUsername', 'toto')
  86. await command.get({ accountName: 'user1@' + servers[1].host })
  87. await command.get({ accountName: 'user2@' + servers[1].host })
  88. await waitJobs(servers)
  89. await command.get({ accountName: 'user1@' + servers[1].host, expectedStatus: HttpStatusCode.OK_200 })
  90. await command.get({ accountName: 'user2@' + servers[1].host, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
  91. })
  92. })
  93. describe('Playlist refresher', function () {
  94. it('Should remove a deleted playlist', async function () {
  95. this.timeout(60000)
  96. await wait(10000)
  97. // Change UUID so the remote server returns a 404
  98. await servers[1].sql.setPlaylistField(playlistUUID2, 'uuid', '304afe4f-39f9-4d49-8ed7-ac57b86b178e')
  99. await servers[0].playlists.get({ playlistId: playlistUUID1 })
  100. await servers[0].playlists.get({ playlistId: playlistUUID2 })
  101. await waitJobs(servers)
  102. await servers[0].playlists.get({ playlistId: playlistUUID1, expectedStatus: HttpStatusCode.OK_200 })
  103. await servers[0].playlists.get({ playlistId: playlistUUID2, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
  104. })
  105. })
  106. after(async function () {
  107. this.timeout(10000)
  108. await cleanupTests(servers)
  109. })
  110. })