Skip to content

Commit

Permalink
Merge pull request #4 from mozilla/accurate-acks
Browse files Browse the repository at this point in the history
Hint property unnecessary to signal acks
  • Loading branch information
mqp authored Jan 4, 2018
2 parents a93018c + 565307b commit 8704445
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ JanusSession.prototype.receive = function(signal) {
}
if (signal.transaction != null) {
var handlers = this.txns[signal.transaction];
if (signal.janus === "ack" && signal.hint) {
if (signal.janus === "ack") {
// this is an ack of an asynchronously-processed request, we should wait
// to resolve the promise until the actual response comes in
} else if (handlers != null) {
Expand Down
2 changes: 1 addition & 1 deletion minijanus.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ JanusSession.prototype.receive = function(signal) {
}
if (signal.transaction != null) {
var handlers = this.txns[signal.transaction];
if (signal.janus === "ack" && signal.hint) {
if (signal.janus === "ack") {
// this is an ack of an asynchronously-processed request, we should wait
// to resolve the promise until the actual response comes in
} else if (handlers != null) {
Expand Down
20 changes: 14 additions & 6 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ test('transactions are detected and matched up', function(t) {
var bq = session.send({ transaction: "wigs" });
var cq = session.send({ transaction: "pigs" });

session.receive({ transaction: "figs", janus: "ack" });
session.receive({ transaction: "wigs", janus: "ack" });
session.receive({ transaction: "pigs", janus: "ack", hint: "Asynchronously processing some pigs." });

session.receive({ transaction: "pigs", rats: "pats" });
session.receive({ just: "kidding" });
session.receive({}, t);
Expand All @@ -27,17 +31,21 @@ test('transaction timeouts happen', function(t) {
var session = new mj.JanusSession(signal => {}, { timeoutMs: 5, keepaliveMs: null });

var aq = session.send({ transaction: "lazy" }).then(
resp => t.error(true, "Request should have failed!"),
err => t.ok(true, "Timeout should have fired!")
resp => { t.fail("Request should have failed!"); return resp; },
err => { t.pass("Timeout should have fired!"); return err; }
);
var bq = session.send({ transaction: "hasty" }).then(
resp => t.ok(true, "Request should have succeeded!"),
err => t.error(true, "Timeout shouldn't have fired!")
resp => { t.pass("Request should have succeeded!"); return resp; },
err => { t.fail("Timeout shouldn't have fired!"); return err; }
);

setTimeout(() => session.receive({ transaction: "hasty", "phew": "just-in-time" }, 1));
session.receive({ transaction: "lazy", janus: "ack" });
session.receive({ transaction: "hasty", janus: "ack" });

setTimeout(() => session.receive({ transaction: "hasty", phew: "just-in-time" }, 1));

Promise.all([aq, bq]).then(() => {
Promise.all([aq, bq]).then(results => {
t.deepEqual(results[1], { transaction: "hasty", phew: "just-in-time" });
t.deepEqual(session.txns, {});
t.end();
});
Expand Down

0 comments on commit 8704445

Please sign in to comment.