mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-28 08:05:51 +00:00
Fix pathfind queuing and add unit test
This commit is contained in:
@@ -1803,9 +1803,20 @@ Remote.prototype.createPathFind = function(options, callback) {
|
|||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
pathFind.on('update', (data) => {
|
pathFind.on('update', (data) => {
|
||||||
if (data.full_reply) {
|
if (data.full_reply && !data.closed) {
|
||||||
pathFind.close();
|
this._cur_path_find = null;
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
|
// "A client can only have one pathfinding request open at a time.
|
||||||
|
// If another pathfinding request is already open on the same
|
||||||
|
// connection, the old request is automatically closed and replaced
|
||||||
|
// with the new request."
|
||||||
|
// - ripple.com/build/rippled-apis/#path-find-create
|
||||||
|
if (this._queued_path_finds.length > 0) {
|
||||||
|
const pathfind = this._queued_path_finds.shift();
|
||||||
|
this.createPathFind(pathfind.options, pathfind.callback);
|
||||||
|
} else {
|
||||||
|
pathFind.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
pathFind.on('error', callback);
|
pathFind.on('error', callback);
|
||||||
@@ -2145,19 +2156,8 @@ Remote.prototype.requestPathFindCreate = function(options, callback) {
|
|||||||
|
|
||||||
Remote.prototype.requestPathFindClose = function(callback) {
|
Remote.prototype.requestPathFindClose = function(callback) {
|
||||||
const request = new Request(this, 'path_find');
|
const request = new Request(this, 'path_find');
|
||||||
|
|
||||||
request.message.subcommand = 'close';
|
request.message.subcommand = 'close';
|
||||||
request.callback((error, data) => {
|
request.callback(callback);
|
||||||
this._cur_path_find = null;
|
|
||||||
if (this._queued_path_finds.length > 0) {
|
|
||||||
const pathfind = this._queued_path_finds.shift();
|
|
||||||
this.createPathFind(pathfind.options, pathfind.callback);
|
|
||||||
}
|
|
||||||
if (callback) {
|
|
||||||
callback(error, data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -570,6 +570,18 @@ describe('RippleAPI', function() {
|
|||||||
_.partial(checkResult, responses.getPaths.XrpToUsd, 'getPaths'));
|
_.partial(checkResult, responses.getPaths.XrpToUsd, 'getPaths'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getPaths - queuing', function() {
|
||||||
|
return Promise.all([
|
||||||
|
this.api.getPaths(requests.getPaths.normal),
|
||||||
|
this.api.getPaths(requests.getPaths.UsdToUsd),
|
||||||
|
this.api.getPaths(requests.getPaths.XrpToXrp)
|
||||||
|
]).then(results => {
|
||||||
|
checkResult(responses.getPaths.XrpToUsd, 'getPaths', results[0]);
|
||||||
|
checkResult(responses.getPaths.UsdToUsd, 'getPaths', results[1]);
|
||||||
|
checkResult(responses.getPaths.XrpToXrp, 'getPaths', results[2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// @TODO
|
// @TODO
|
||||||
// need decide what to do with currencies/XRP:
|
// need decide what to do with currencies/XRP:
|
||||||
// if add 'XRP' in currencies, then there will be exception in
|
// if add 'XRP' in currencies, then there will be exception in
|
||||||
|
|||||||
@@ -271,7 +271,8 @@ module.exports = function(port) {
|
|||||||
request.id, request.source_account, request.destination_account,
|
request.id, request.source_account, request.destination_account,
|
||||||
request.destination_amount);
|
request.destination_amount);
|
||||||
}
|
}
|
||||||
conn.send(response);
|
// delay response to simulate calculation time so we can test queuing
|
||||||
|
setTimeout(() => conn.send(response), 20);
|
||||||
});
|
});
|
||||||
|
|
||||||
return mock;
|
return mock;
|
||||||
|
|||||||
Reference in New Issue
Block a user