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

Hint property unnecessary to signal acks #4

Merged
merged 1 commit into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 });

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