Skip to content

Commit

Permalink
feat(tests): new scanner test
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 4, 2018
1 parent 378a8e7 commit 0c6544f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 74 deletions.
74 changes: 5 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"electron": "1.7.11",
"electron-builder": "^19.43.3",
"friendly-errors-webpack-plugin": "^1.6.1",
"mocha": "^4.0.1",
"mocha": "^4.1.0",
"source-map-support": "^0.5.0",
"spectron": "^3.7.2",
"style-loader": "^0.19.0",
Expand Down
6 changes: 4 additions & 2 deletions src/background/bt/cpu-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let keepTime = process.hrtime()
let keepUsage = process.cpuUsage()
let sw = false

setInterval(() => {
const cpuTimer = setInterval(() => {
if(!sw) {
keepTime = process.hrtime();
keepUsage = process.cpuUsage();
Expand All @@ -14,9 +14,11 @@ setInterval(() => {
startTime = keepTime;
startUsage = keepUsage;
sw = false;
}
}
}, 500)

cpuTimer.unref()

module.exports = () => {
function secNSec2ms (secNSec) {
return secNSec[0] * 1000 + secNSec[1] / 1000000
Expand Down
3 changes: 2 additions & 1 deletion src/background/bt/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
module.exports = class {
constructor() {
this.generate()
setInterval(()=> this.generate(), 60000*15)
const it = setInterval(() => this.generate(), 60000*15)
it.unref()
}

isValid(t) {
Expand Down
2 changes: 1 addition & 1 deletion src/background/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const fs = require('fs');
const debug = require('debug')('config')

let configPath = 'config.json'
if(app.getPath("userData") && app.getPath("userData").length > 0)
if(app && app.getPath("userData") && app.getPath("userData").length > 0)
{
configPath = app.getPath("userData") + '/config.json'
}
Expand Down
25 changes: 25 additions & 0 deletions tests/spider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect } from "chai";

const client = new (require('../src/background/bt/client'))
const spider = new (require('../src/background/bt/spider'))(client)

describe("spider check", () => {
it("listen", function() {
spider.listen(4445)
})

it("enshure hash recive", function(done) {
this.timeout(100000);
spider.once('ensureHash', () => done())
})

it("get metadata", function(done) {
this.timeout(120000);
client.once('complete', function (metadata, infohash, rinfo) {
expect(Buffer.isBuffer(infohash))
expect(infohash.length == 20)
spider.close(() => done())
})
});

});

0 comments on commit 0c6544f

Please sign in to comment.