Skip to content

Commit

Permalink
Follow up test fixes to restore explicit serialport test with abort m…
Browse files Browse the repository at this point in the history
…echanism
  • Loading branch information
rwaldron committed Jul 8, 2015
1 parent 6b57289 commit dd90b93
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 48 deletions.
8 changes: 7 additions & 1 deletion lib/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ var Serial = {
// If no ports are detected...
if (!length) {

if (IS_TEST_MODE && this.abort) {
return;
}

// Create an attempt counter
if (!Serial.attempts[Serial.used.length]) {
Serial.attempts[Serial.used.length] = 0;
Expand Down Expand Up @@ -484,7 +488,6 @@ util.inherits(Board, Emitter);
};
});


Board.prototype.serialize = function(filter) {
var blacklist = this.serialize.blacklist;
var special = this.serialize.special;
Expand Down Expand Up @@ -1137,6 +1140,9 @@ if (IS_TEST_MODE) {

Board.purge = function() {
Board.Pins.normalize.clear();
Repl.isActive = false;
Repl.isBlocked = true;
Repl.ref = null;

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jul 8, 2015

Author Owner

@dtex This was the silver bullet.

This comment has been minimized.

Copy link
@dtex

dtex Jul 8, 2015

Collaborator

It still bombs out after 10 seconds. Note: You wouldn't see it unless you do something to make the tests run longer.

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jul 8, 2015

Author Owner

I need more to go on if I'm going to help solve this :P

This comment has been minimized.

Copy link
@dtex

dtex Jul 8, 2015

Collaborator

Sorry. Check out PR #858 . It has additional extended tests that take over 10 seconds to complete. If you run grunt nodeunit:complete, at around the 10 second mark an error is thrown:

Testing stepper.js.................OK
Testing switch.js...OK
Testing temperature.js...............OK
Testing wii.js........OK
Testing piezo.js.....OK
Testing led.js............OK
Testing servo.js...Fatal error: Uncaught, unspecified "error" event.
Donovans-MacBook-Pro:johnny-five dtex$ 

But the error isn't coming from extended/servo.js it's being thrown by the explicit test in test/board.js. The call to new Serialport() is timing out.

Sorry I was unclear. Is this helpful?

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jul 10, 2015

Author Owner

Is this helpful?

Yes, very! Thanks :)

boards.length = 0;
};
}
Expand Down
37 changes: 21 additions & 16 deletions test/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("es6-shim");


var MockFirmata = require("./util/mock-firmata"),
// SerialPort = require("./util/mock-serial").SerialPort,
SerialPort = require("./util/mock-serial").SerialPort,
five = require("../lib/johnny-five.js"),
sinon = require("sinon"),
__ = require("../lib/fn.js"),
Expand Down Expand Up @@ -44,24 +44,28 @@ exports["Board"] = {
done();
},

// explicit: function(test) {
// test.expect(1);
explicit: function(test) {
test.expect(1);

// var sp = new SerialPort("/dev/foo", {
// baudrate: 57600,
// buffersize: 128
// });
var sp = new SerialPort("/dev/foo", {
baudrate: 57600,
buffersize: 128
});

// var board = new Board({
// port: sp,
// debug: false,
// repl: false
// });
var board = new Board({
port: sp,
debug: false,
repl: false
});

// test.equal(board.io.sp, sp);
test.equal(board.io.sp, sp);

// test.done();
// },
board.abort = true;

setImmediate(function() {
test.done();
});
},

ioIsReady: function(test) {
test.expect(2);
Expand Down Expand Up @@ -322,6 +326,7 @@ exports["Boards"] = {

tearDown: function(done) {
Board.purge();

if (this.replInit) {
this.replInit.restore();
}
Expand Down Expand Up @@ -419,7 +424,7 @@ exports["Boards"] = {
}]);

boards.on("ready", function() {
test.equal(this.replInit.called, true);
test.equal(this.replInit.callCount, 1);
test.done();
}.bind(this));

Expand Down
87 changes: 58 additions & 29 deletions test/esc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ var MockFirmata = require("./util/mock-firmata"),
Board = five.Board,
ESC = five.ESC;

This comment has been minimized.

Copy link
@rwaldron

rwaldron Jul 8, 2015

Author Owner

Yiiiiikes.


var io = new MockFirmata();
var board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

exports["ESC"] = {
setUp: function(done) {
this.clock = sinon.useFakeTimers();
this.servoWrite = sinon.spy(board.io, "servoWrite");
this.servoWrite = sinon.spy(MockFirmata.prototype, "servoWrite");

var io = new MockFirmata();
this.board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

this.esc = new ESC({
pin: 12,
board: board
board: this.board
});


this.proto = [{
name: "speed"
}, {
Expand Down Expand Up @@ -52,6 +53,7 @@ exports["ESC"] = {
},

tearDown: function(done) {
Board.purge();
this.clock.restore();
this.servoWrite.restore();

Expand Down Expand Up @@ -91,7 +93,7 @@ exports["ESC"] = {

this.esc = new ESC({
pin: 12,
board: board,
board: this.board,
startAt: 1
});

Expand Down Expand Up @@ -240,11 +242,21 @@ exports["ESC"] = {
exports["ESC - PCA9685"] = {
setUp: function(done) {
this.clock = sinon.useFakeTimers();
this.writeSpy = sinon.spy(board.io, "i2cWrite");
this.readSpy = sinon.spy(board.io, "i2cRead");
this.writeSpy = sinon.spy(MockFirmata.prototype, "i2cWrite");
this.readSpy = sinon.spy(MockFirmata.prototype, "i2cRead");

var io = new MockFirmata();
this.board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

this.esc = new ESC({
pin: 0,
board: board,
board: this.board,
controller: "PCA9685",
address: 0x40
});
Expand All @@ -253,6 +265,7 @@ exports["ESC - PCA9685"] = {
},

tearDown: function(done) {
Board.purge();
this.writeSpy.restore();
this.readSpy.restore();
this.clock.restore();
Expand All @@ -264,7 +277,7 @@ exports["ESC - PCA9685"] = {

var esc = new ESC({
pin: 0,
board: board,
board: this.board,
controller: "PCA9685",
address: 0x40
});
Expand All @@ -278,7 +291,7 @@ exports["ESC - PCA9685"] = {

var esc = new ESC({
pin: 0,
board: board,
board: this.board,
controller: "PCA9685"
});

Expand Down Expand Up @@ -307,10 +320,20 @@ exports["ESC - PCA9685"] = {
exports["ESC - FORWARD_REVERSE"] = {
setUp: function(done) {
this.clock = sinon.useFakeTimers();
var io = new MockFirmata();
this.board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

done();
},

tearDown: function(done) {
Board.purge();
this.clock.restore();
done();
},
Expand All @@ -321,8 +344,9 @@ exports["ESC - FORWARD_REVERSE"] = {
new ESC({
device: "FORWARD_REVERSE",
pin: 11,
});
});
board: this.board
}.bind(this));
}.bind(this));

test.done();
},
Expand All @@ -334,7 +358,7 @@ exports["ESC - FORWARD_REVERSE"] = {
device: "FORWARD_REVERSE",
neutral: 50,
pin: 11,
board: board,
board: this.board,
});

test.ok(spy.calledOnce);
Expand All @@ -352,7 +376,7 @@ exports["ESC - FORWARD_REVERSE"] = {
device: "FORWARD_REVERSE",
neutral: 50,
pin: 11,
board: board,
board: this.board,
});

spy.reset();
Expand All @@ -378,7 +402,7 @@ exports["ESC - FORWARD_REVERSE"] = {
device: "FORWARD_REVERSE",
neutral: 50,
pin: 11,
board: board,
board: this.board,
});

spy.reset();
Expand All @@ -403,7 +427,7 @@ exports["ESC - FORWARD_REVERSE"] = {
device: "FORWARD_REVERSE",
neutral: 50,
pin: 11,
board: board,
board: this.board,
});

var spy = sinon.spy(esc, "write");
Expand All @@ -423,27 +447,31 @@ exports["ESC - FORWARD_REVERSE"] = {

exports["ESC.Array"] = {
setUp: function(done) {
var board = new Board({
io: new MockFirmata(),

var io = new MockFirmata();
this.board = new Board({
io: io,
debug: false,
repl: false
});

io.emit("ready");

ESC.purge();

this.a = new ESC({
pin: 3,
board: board
board: this.board
});

this.b = new ESC({
pin: 6,
board: board
board: this.board
});

this.c = new ESC({
pin: 9,
board: board
board: this.board
});

this.spies = [
Expand All @@ -459,6 +487,7 @@ exports["ESC.Array"] = {
},

tearDown: function(done) {
Board.purge();
this.spies.forEach(function(value) {
this[value].restore();
}.bind(this));
Expand Down
9 changes: 7 additions & 2 deletions test/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var MockFirmata = require("./util/mock-firmata"),
Board = five.Board;

exports["Repl"] = {
setUp: function(done) {
done();
},
tearDown: function(done) {
Board.purge();
done();
},
repl: function(test) {
var io = new MockFirmata();
var board = new Board({
Expand All @@ -17,8 +24,6 @@ exports["Repl"] = {
test.ok(this.repl === board.repl);
test.ok(this.repl instanceof Repl);
test.ok(this.repl.context);
Repl.isBlocked = true;
Board.purge();
test.done();
});

Expand Down

0 comments on commit dd90b93

Please sign in to comment.