import 'mocha' ; import * as chai from 'chai' ; import { Job } from '@shared/models' ; import { cleanupTests , createMultipleServers , doubleFollow , PeerTubeServer , setAccessTokensToServers , waitJobs } from '@shared/server-commands' ; const expect = chai . expect ; describe ( 'Test slow follows' , function ( ) { let servers = [ ] ; let afterFollows ; before ( async function ( ) { this . timeout ( 60000 ) ; servers = await createMultipleServers ( 3 ) ; await setAccessTokensToServers ( servers ) ; await doubleFollow ( servers [ 0 ] , servers [ 1 ] ) ; await doubleFollow ( servers [ 0 ] , servers [ 2 ] ) ; afterFollows = new Date ( ) ; for ( let i = 0 ; i < 5 ; i ++ ) { await servers [ 0 ] . videos . quickUpload ( { name : 'video ' + i } ) ; } await waitJobs ( servers ) ; } ) ; it ( 'Should only have broadcast jobs' , async function ( ) { const { data } = await servers [ 0 ] . jobs . list ( { jobType : 'activitypub-http-unicast' , sort : '-createdAt' } ) ; for ( const job of data ) { expect ( new Date ( job . createdAt ) ) . below ( afterFollows ) ; } } ) ; it ( 'Should process bad follower' , async function ( ) { this . timeout ( 30000 ) ; await servers [ 1 ] . kill ( ) ; await servers [ 0 ] . videos . quickUpload ( { name : 'video 6' } ) ; await waitJobs ( servers [ 0 ] ) ; afterFollows = new Date ( ) ; const filter = ( job ) => new Date ( job . createdAt ) > afterFollows ; await servers [ 0 ] . videos . quickUpload ( { name : 'video 7' } ) ; await waitJobs ( servers [ 0 ] ) ; const resBroadcast = await servers [ 0 ] . jobs . list ( { jobType : 'activitypub-http-broadcast' , sort : '-createdAt' } ) ; const resUnicast = await servers [ 0 ] . jobs . list ( { jobType : 'activitypub-http-unicast' , sort : '-createdAt' } ) ; const broadcast = resBroadcast . data . filter ( filter ) ; const unicast = resUnicast . data . filter ( filter ) ; expect ( unicast ) . to . have . lengthOf ( 2 ) ; expect ( broadcast ) . to . have . lengthOf ( 2 ) ; for ( const u of unicast ) { expect ( u . data . uri ) . to . equal ( servers [ 1 ] . url + '/inbox' ) ; } for ( const b of broadcast ) { expect ( b . data . uris ) . to . have . lengthOf ( 1 ) ; expect ( b . data . uris [ 0 ] ) . to . equal ( servers [ 2 ] . url + '/inbox' ) ; } } ) ; after ( async function ( ) { await cleanupTests ( servers ) ; } ) ; } ) ;