bittorrent-tracker/test/client-large-torrent.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

import Client from '../index.js'
import common from './common.js'
import fixtures from 'webtorrent-fixtures'
import test from 'tape'
2014-04-19 06:08:17 +00:00
2020-10-29 04:57:47 +00:00
const peerId = Buffer.from('01234567890123456789')
2014-04-19 06:08:17 +00:00
function testLargeTorrent (t, serverType) {
t.plan(9)
2014-04-19 06:08:17 +00:00
2021-06-15 01:54:41 +00:00
common.createServer(t, serverType, (server, announceUrl) => {
2020-10-29 04:57:47 +00:00
const client = new Client({
infoHash: fixtures.sintel.parsedTorrent.infoHash,
2020-04-25 09:34:40 +00:00
peerId,
port: 6881,
announce: announceUrl,
wrtc: {}
})
2014-04-19 06:08:17 +00:00
if (serverType === 'ws') common.mockWebsocketTracker(client)
2021-06-15 01:54:41 +00:00
client.on('error', err => { t.error(err) })
client.on('warning', err => { t.error(err) })
2021-06-15 01:54:41 +00:00
client.once('update', data => {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
2014-05-24 04:02:53 +00:00
client.update()
2021-06-15 01:54:41 +00:00
client.once('update', data => {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
client.stop()
2021-06-15 01:54:41 +00:00
client.once('update', data => {
t.equal(data.announce, announceUrl)
t.equal(typeof data.complete, 'number')
t.equal(typeof data.incomplete, 'number')
2014-05-24 04:02:53 +00:00
server.close()
client.destroy()
})
2014-05-24 03:43:45 +00:00
})
2014-05-24 04:02:53 +00:00
})
client.start()
})
}
2021-06-15 01:54:41 +00:00
test('http: large torrent: client.start()', t => {
testLargeTorrent(t, 'http')
})
2021-06-15 01:54:41 +00:00
test('udp: large torrent: client.start()', t => {
testLargeTorrent(t, 'udp')
})
2021-06-15 01:54:41 +00:00
test('ws: large torrent: client.start()', t => {
testLargeTorrent(t, 'ws')
2014-04-19 06:08:17 +00:00
})