Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use memory chunk store for unit tests #871

Merged
merged 1 commit into from Jul 23, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Make downloading tests work on memory store to ensure the sore is empty.

Corrected webseed test to follow fixtures and tracker magnet.
  • Loading branch information
yciabaud committed Jul 21, 2016
commit e7a08de25ab896b9e736326b833cec34ada42db8
@@ -1,6 +1,7 @@
var DHT = require('bittorrent-dht/server')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var MemoryChunkStore = require('memory-chunk-store')
var networkAddress = require('network-address')
var series = require('run-series')
var test = require('tape')
@@ -34,7 +35,7 @@ test('Download using DHT (via magnet uri)', function (t) {
client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

var torrent = client1.add(fixtures.leaves.parsedTorrent)
var torrent = client1.add(fixtures.leaves.parsedTorrent, {store: MemoryChunkStore})

torrent.on('dhtAnnounce', function () {
t.pass('finished dht announce')
@@ -89,7 +90,7 @@ test('Download using DHT (via magnet uri)', function (t) {
})
})

client2.add(fixtures.leaves.magnetURI)
client2.add(fixtures.leaves.magnetURI, {store: MemoryChunkStore})

var gotBuffer = false
var gotDone = false
@@ -1,6 +1,7 @@
var DHT = require('bittorrent-dht/server')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var test = require('tape')
var WebTorrent = require('../../')
@@ -33,7 +34,7 @@ test('Download using DHT (via .torrent file)', function (t) {
client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

var torrent = client1.add(fixtures.leaves.parsedTorrent)
var torrent = client1.add(fixtures.leaves.parsedTorrent, {store: MemoryChunkStore})

torrent.on('ready', function () {
// torrent metadata has been fetched -- sanity check it
@@ -99,7 +100,7 @@ test('Download using DHT (via .torrent file)', function (t) {
}
})

client2.add(fixtures.leaves.parsedTorrent)
client2.add(fixtures.leaves.parsedTorrent, {store: MemoryChunkStore})
}
], function (err) {
t.error(err)
@@ -1,5 +1,6 @@
var fixtures = require('webtorrent-fixtures')
var http = require('http')
var MemoryChunkStore = require('memory-chunk-store')
var test = require('tape')
var WebTorrent = require('../../')

@@ -32,7 +33,7 @@ test('Download metadata for magnet URI with xs parameter', function (t) {

createServer(fixtures.leaves.torrent, function (url, server) {
var encodedUrl = encodeURIComponent(url)
client.add(fixtures.leaves.magnetURI + '&xs=' + encodedUrl, function (torrent) {
client.add(fixtures.leaves.magnetURI + '&xs=' + encodedUrl, {store: MemoryChunkStore}, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
client.destroy(function (err) { t.error(err, 'client destroyed') })
server.close(function () { t.pass('server closed') })
@@ -56,7 +57,7 @@ test('Download metadata for magnet URI with 2 xs parameters', function (t) {

var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2

client.add(uri, function (torrent) {
client.add(uri, {store: MemoryChunkStore}, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
client.destroy(function (err) { t.error(err, 'client destroyed') })
server1.close(function () { t.pass('server closed') })
@@ -79,7 +80,7 @@ test('Download metadata for magnet URI with 2 xs parameters, with 1 invalid prot
var encodedUrl2 = encodeURIComponent(url)
var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2

client.add(uri, function (torrent) {
client.add(uri, {store: MemoryChunkStore}, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
client.destroy(function (err) { t.error(err, 'client destroyed') })
server.close(function () { t.pass('server closed') })
@@ -100,7 +101,7 @@ test('Download metadata for magnet URI with 2 xs parameters, with 1 404 URL', fu
var encodedUrl2 = encodeURIComponent(url)
var uri = fixtures.leaves.magnetURI + '&xs=' + encodedUrl1 + '&xs=' + encodedUrl2

client.add(uri, function (torrent) {
client.add(uri, {store: MemoryChunkStore}, function (torrent) {
t.equal(torrent.files[0].name, 'Leaves of Grass by Walt Whitman.epub')
client.destroy(function (err) { t.error(err, 'client destroyed') })
server.close(function () { t.pass('server closed') })
@@ -116,7 +117,7 @@ test('Download metadata magnet URI with unsupported protocol in xs parameter', f
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })

client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'))
client.add(fixtures.leaves.magnetURI + '&xs=' + encodeURIComponent('invalidurl:example'), {store: MemoryChunkStore})

setTimeout(function () {
// no crash by now
@@ -1,5 +1,6 @@
var DHT = require('bittorrent-dht/server')
var fixtures = require('webtorrent-fixtures')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var test = require('tape')
var WebTorrent = require('../../')
@@ -28,7 +29,7 @@ test('private torrent should not use DHT', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })

var torrent = client.add(fixtures.bunny.parsedTorrent)
var torrent = client.add(fixtures.bunny.parsedTorrent, {store: MemoryChunkStore})

torrent.on('dhtAnnounce', function () {
t.fail('client announced to dht')
@@ -76,7 +77,7 @@ test('public torrent should use DHT', function (t) {
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })

var torrent = client.add(fixtures.leaves.parsedTorrent)
var torrent = client.add(fixtures.leaves.parsedTorrent, {store: MemoryChunkStore})

torrent.on('dhtAnnounce', function () {
t.pass('client announced to dht')
@@ -1,6 +1,7 @@
var extend = require('xtend')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
@@ -15,7 +16,7 @@ test('Download using HTTP tracker (via magnet uri)', function (t) {
})

function magnetDownloadTest (t, serverType) {
t.plan(10)
t.plan(11)

This comment has been minimized.

Copy link
@yciabaud

yciabaud Jul 21, 2016

Author Contributor

This test was not passing with an empty store, I assume this is the good number.

This comment has been minimized.

Copy link
@feross

feross Jul 23, 2016

Member

It looks like 10 is the right number, we should figure out why this needed to be changed to 11 to pass with an empty store.

This comment has been minimized.

Copy link
@feross

feross Jul 23, 2016

Member

Okay, so this was a timing thing. Basically now noPeers is getting emitted twice because the tracker gets sent a 'started' then a 'completed' message and both times there are no peers in the response. I changed the .on('noPeers') to .once('noPeers') so this will be more reliable.

This comment has been minimized.

Copy link
@yciabaud

yciabaud Jul 23, 2016

Author Contributor

Ok thank you

This comment has been minimized.

Copy link
@feross

var tracker = new TrackerServer(
serverType === 'udp' ? { http: false, ws: false } : { udp: false, ws: false }
@@ -70,7 +71,7 @@ function magnetDownloadTest (t, serverType) {
})
})

client1.add(parsedTorrent)
client1.add(parsedTorrent, {store: MemoryChunkStore})
},

function (cb) {
@@ -102,7 +103,7 @@ function magnetDownloadTest (t, serverType) {
}
})

client2.add(magnetURI)
client2.add(magnetURI, {store: MemoryChunkStore})
}

], function (err) {
@@ -1,6 +1,7 @@
var extend = require('xtend')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var test = require('tape')
var TrackerServer = require('bittorrent-tracker/server')
@@ -65,15 +66,15 @@ function torrentDownloadTest (t, serverType) {
torrent.load(fs.createReadStream(fixtures.leaves.contentPath), cb)
})

client1.add(parsedTorrent)
client1.add(parsedTorrent, {store: MemoryChunkStore})
},

function (cb) {
client2 = new WebTorrent({ dht: false })
client2.on('error', function (err) { t.fail(err) })
client2.on('warning', function (err) { t.fail(err) })

client2.add(parsedTorrent)
client2.add(parsedTorrent, {store: MemoryChunkStore})

client2.on('torrent', function (torrent) {
torrent.files.forEach(function (file) {
@@ -2,6 +2,7 @@ var finalhandler = require('finalhandler')
var fixtures = require('webtorrent-fixtures')
var http = require('http')
var path = require('path')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var serveStatic = require('serve-static')
var test = require('tape')
@@ -10,7 +11,7 @@ var WebTorrent = require('../../')
test('Download using webseed (via magnet uri)', function (t) {
t.plan(9)

var serve = serveStatic(path.join(__dirname, 'content'))
var serve = serveStatic(path.dirname(fixtures.leaves.contentPath))

This comment has been minimized.

Copy link
@yciabaud

yciabaud Jul 21, 2016

Author Contributor

Assets are now in the fixtures module.

This comment has been minimized.

Copy link
@feross

feross Jul 23, 2016

Member

Good catch!

var httpServer = http.createServer(function (req, res) {
var done = finalhandler(req, res)
serve(req, res, done)
@@ -51,7 +52,7 @@ test('Download using webseed (via magnet uri)', function (t) {
maybeDone()
})

var torrent = client1.add(fixtures.leaves.parsedTorrent)
var torrent = client1.add(fixtures.leaves.parsedTorrent, {store: MemoryChunkStore})

torrent.on('infoHash', function () {
gotListening = true
@@ -91,7 +92,7 @@ test('Download using webseed (via magnet uri)', function (t) {
}
})

var torrent = client2.add(magnetURI)
var torrent = client2.add(magnetURI, {store: MemoryChunkStore})

torrent.on('infoHash', function () {
torrent.addPeer('127.0.0.1:' + client1.address().port)
@@ -2,6 +2,7 @@ var extend = require('xtend')
var finalhandler = require('finalhandler')
var fixtures = require('webtorrent-fixtures')
var http = require('http')
var MemoryChunkStore = require('memory-chunk-store')
var path = require('path')
var series = require('run-series')
var serveStatic = require('serve-static')
@@ -15,7 +16,7 @@ test('Download using webseed (via .torrent file)', function (t) {

var httpServer = http.createServer(function (req, res) {
var done = finalhandler(req, res)
serveStatic(path.join(__dirname, 'content'))(req, res, done)
serveStatic(path.dirname(fixtures.leaves.contentPath))(req, res, done)
})
var client

@@ -59,7 +60,7 @@ test('Download using webseed (via .torrent file)', function (t) {
}
})

client.add(parsedTorrent)
client.add(parsedTorrent, {store: MemoryChunkStore})
}
], function (err) {
t.error(err)
@@ -1,6 +1,7 @@
var DHT = require('bittorrent-dht/server')
var fixtures = require('webtorrent-fixtures')
var fs = require('fs')
var MemoryChunkStore = require('memory-chunk-store')
var series = require('run-series')
var test = require('tape')
var WebTorrent = require('../../')
@@ -29,7 +30,7 @@ test('Seed and download a file at the same time', function (t) {
client1.on('error', function (err) { t.fail(err) })
client1.on('warning', function (err) { t.fail(err) })

var torrent = client1.add(fixtures.leaves.torrent)
var torrent = client1.add(fixtures.leaves.torrent, {store: MemoryChunkStore})

torrent.on('dhtAnnounce', function () {
t.pass('client1 finished dht announce')
@@ -60,7 +61,7 @@ test('Seed and download a file at the same time', function (t) {
client2.on('error', function (err) { t.fail(err) })
client2.on('warning', function (err) { t.fail(err) })

var torrent = client2.add(fixtures.alice.torrent)
var torrent = client2.add(fixtures.alice.torrent, {store: MemoryChunkStore})

torrent.on('dhtAnnounce', function () {
t.pass('client2 finished dht announce')
@@ -82,7 +83,7 @@ test('Seed and download a file at the same time', function (t) {
},

function (cb) {
client1.add(fixtures.alice.magnetURI)
client1.add(fixtures.alice.magnetURI, {store: MemoryChunkStore})

client1.on('torrent', function (torrent) {
torrent.files[0].getBuffer(function (err, buf) {
@@ -99,7 +100,7 @@ test('Seed and download a file at the same time', function (t) {
})
})

client2.add(fixtures.leaves.magnetURI)
client2.add(fixtures.leaves.magnetURI, {store: MemoryChunkStore})

client2.on('torrent', function (torrent) {
torrent.files[0].getBuffer(function (err, buf) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.