forked from crossbario/autobahn-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use incrementing IDs for session requests (crossbario#377)
* Use incrementing IDs for session requests. Fixes crossbario#160. * Remove global scope random ID generation. We also weren't doing anything serializer specific. Relates to crossbario#160. * Restore global scope ID generation function to the util module. Per request of @oberstet in crossbario#377. Also make it inclusive of the max by adding 1 to the floor. Relates to crossbario#160.
- Loading branch information
1 parent
09333e6
commit e5a1f14
Showing
6 changed files
with
121 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// AutobahnJS - http://autobahn.ws, http://wamp.ws | ||
// | ||
// A JavaScript library for WAMP ("The Web Application Messaging Protocol"). | ||
// | ||
// Copyright (c) Crossbar.io Technologies GmbH and contributors | ||
// | ||
// Licensed under the MIT License. | ||
// http://www.opensource.org/licenses/mit-license.php | ||
// | ||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
var autobahn = require('./../index.js'); | ||
var testutil = require('./testutil.js'); | ||
|
||
var REGISTER_MSG_TYPE = 64; | ||
var CALL_MSG_TYPE = 48; | ||
|
||
exports.testRpcRequestIdSequence = function (testcase) { | ||
|
||
testcase.expect(2); | ||
|
||
var test = new testutil.Testlog("test/test_rpc_request_id_sequence.txt"); | ||
|
||
var connection = new autobahn.Connection(testutil.config); | ||
|
||
connection.onopen = function (session) { | ||
|
||
test.log('Connected'); | ||
|
||
// Hijack invocation processing to collect request IDs of incoming calls. | ||
var sent_request_ids = []; | ||
var original_send_wamp = session._send_wamp; | ||
session._send_wamp = function(msg) { | ||
if ((msg[0] === CALL_MSG_TYPE) || ((msg[0] === REGISTER_MSG_TYPE))) { | ||
var requestId = msg[1]; | ||
test.log('' + 'Sent call with id ' + requestId); | ||
sent_request_ids.push(requestId); | ||
} | ||
return original_send_wamp(msg) | ||
}; | ||
|
||
function noop() { return null; } | ||
|
||
session.register('com.myapp.do_nothing', noop).then( | ||
function () { | ||
test.log("Procedure registered."); | ||
|
||
// Enforce sequential execution of RPCs to get "stable" test results | ||
var d = session.call('com.myapp.do_nothing'); | ||
d = d.then(function (res) { | ||
test.log('Received response.'); | ||
return session.call('com.myapp.do_nothing') | ||
}); | ||
d = d.then(function (res) { | ||
test.log('Received response.'); | ||
return session.call('com.myapp.do_nothing') | ||
}); | ||
d = d.then(function (res) { | ||
test.log('Received response.'); | ||
}); | ||
|
||
d.then(function () { | ||
test.log("All calls made."); | ||
testcase.deepEqual(sent_request_ids, [1, 2, 3, 4]); | ||
|
||
session._send_wamp = original_send_wamp; | ||
connection.close(); | ||
|
||
var chk = test.check(); | ||
testcase.ok(!chk, chk); | ||
testcase.done(); | ||
}); | ||
}, | ||
function () { | ||
test.log("Registration failed!", arguments); | ||
} | ||
); | ||
}; | ||
|
||
connection.open(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
0 "Connected" | ||
1 "Sent call with id 1" | ||
2 "Procedure registered." | ||
3 "Sent call with id 2" | ||
4 "Received response." | ||
5 "Sent call with id 3" | ||
6 "Received response." | ||
7 "Sent call with id 4" | ||
8 "Received response." | ||
9 "All calls made." |