import { Server as WebSocketServer } from 'ws'
import { CONFIG, TRACKER_RATE_LIMITS } from '../initializers/constants'
import { VideoFileModel } from '../models/video/video-file'
+import { parse } from 'url'
const TrackerServer = bitTorrentTracker.Server
function createWebsocketTrackerServer (app: express.Application) {
const server = http.createServer(app)
- const wss = new WebSocketServer({ server: server, path: '/tracker/socket' })
+ const wss = new WebSocketServer({ noServer: true })
+
wss.on('connection', function (ws, req) {
- const ip = proxyAddr(req, CONFIG.TRUST_PROXY)
- ws['ip'] = ip
+ ws['ip'] = proxyAddr(req, CONFIG.TRUST_PROXY)
trackerServer.onWebSocketConnection(ws)
})
+ server.on('upgrade', (request, socket, head) => {
+ const pathname = parse(request.url).pathname
+
+ if (pathname === '/tracker/socket') {
+ wss.handleUpgrade(request, socket, head, ws => wss.emit('connection', ws, request))
+ }
+
+ // Don't destroy socket, we have Socket.IO too
+ })
+
return server
}
let videoUUID3: string
before(async function () {
- this.timeout(30000)
+ this.timeout(60000)
servers = await flushAndRunMultipleServers(2)
})
after(async function () {
+ MockSmtpServer.Instance.kill()
killallServers([ server ])
})
})
+import './users-verification'
+import './user-notifications'
import './blocklist'
import './user-subscriptions'
-import './user-notifications'
import './users'
import './users-multiple-servers'
-import './users-verification'
})
it('Should send a new video notification if the user follows the local video publisher', async function () {
- this.timeout(10000)
+ this.timeout(15000)
await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:9001')
await waitJobs(servers)
})
after(async function () {
+ MockSmtpServer.Instance.kill()
+
killallServers(servers)
})
})
import 'mocha'
import {
registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers,
- userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig
+ userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait
} from '../../../../shared/utils'
import { setAccessTokensToServers } from '../../../../shared/utils/users/login'
import { MockSmtpServer } from '../../../../shared/utils/miscs/email'
})
after(async function () {
+ MockSmtpServer.Instance.kill()
killallServers([ server ])
// Keep the logs if the test failed
-import * as child from 'child_process'
+import { fork, ChildProcess } from 'child_process'
class MockSmtpServer {
private static instance: MockSmtpServer
private started = false
- private emailChildProcess: child.ChildProcess
+ private emailChildProcess: ChildProcess
private emails: object[]
private constructor () {
- this.emailChildProcess = child.fork(`${__dirname}/email-child-process`, [], { silent: true })
+ this.emailChildProcess = fork(`${__dirname}/email-child-process`, [])
+
this.emailChildProcess.on('message', (msg) => {
if (msg.email) {
return this.emails.push(msg.email)
}
})
- process.on('exit', () => {
- this.emailChildProcess.kill()
- })
}
collectEmails (emailsCollection: object[]) {
})
}
+ kill () {
+ process.kill(this.emailChildProcess.pid)
+
+ this.emailChildProcess = null
+ MockSmtpServer.instance = null
+ }
+
static get Instance () {
return this.instance || (this.instance = new this())
}