mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 00:15:51 +00:00
Support a "--noserver" command line option in tests:
* Run npm/integration tests without launching rippled, using a running instance of rippled (possibly in a debugger) instead. * Works for "npm test" and "mocha"
This commit is contained in:
committed by
Nik Bougalis
parent
5d6ea3d75f
commit
a691632995
@@ -22,6 +22,10 @@ This ensures that each test is run against the known
|
|||||||
To use a running `rippled`, particularly one running in a debugger, follow
|
To use a running `rippled`, particularly one running in a debugger, follow
|
||||||
these steps:
|
these steps:
|
||||||
|
|
||||||
|
#### Setup
|
||||||
|
|
||||||
|
##### Using configuration files
|
||||||
|
|
||||||
1. Make a copy of the example configuration file: `cp -i test/config-example.js test/config.js`
|
1. Make a copy of the example configuration file: `cp -i test/config-example.js test/config.js`
|
||||||
|
|
||||||
2. Edit `test/config.js` to select the "debug" server configuration.
|
2. Edit `test/config.js` to select the "debug" server configuration.
|
||||||
@@ -33,36 +37,47 @@ these steps:
|
|||||||
2. Copy and/or rename the `tmp/server/debug/rippled.cfg` file to somewhere
|
2. Copy and/or rename the `tmp/server/debug/rippled.cfg` file to somewhere
|
||||||
convenient.
|
convenient.
|
||||||
|
|
||||||
4. Start `rippled` (in a debugger) with command line options
|
##### Using the command line
|
||||||
|
|
||||||
|
1. Create a `rippled.cfg` file for the tests.
|
||||||
|
1. Run `npm test --noserver`. The tests will fail. **This failure is expected.**
|
||||||
|
2. Copy and/or rename the `tmp/server/alpha/rippled.cfg` file to somewhere
|
||||||
|
convenient.
|
||||||
|
|
||||||
|
#### Running the tests.
|
||||||
|
|
||||||
|
1. Start `rippled` (in a debugger) with command line options
|
||||||
`-av --conf <rippled-created-above.cfg>`.
|
`-av --conf <rippled-created-above.cfg>`.
|
||||||
|
|
||||||
5. Set any desired breakpoints in the `rippled` source.
|
2. Set any desired breakpoints in the `rippled` source.
|
||||||
|
|
||||||
6. Running one test per [_genesis ledger_][genesis_ledger] is highly recommended.
|
3. Running one test per [_genesis ledger_][genesis_ledger] is highly recommended.
|
||||||
If the relevant `.js` file contains more than one test, change `test(` to
|
If the relevant `.js` file contains more than one test, change `test(` to
|
||||||
`test.only(` for the single desired test.
|
`test.only(` for the single desired test.
|
||||||
* To run multiple tests, change `test(` to `test.skip(` for any undesired tests
|
* To run multiple tests, change `test(` to `test.skip(` for any undesired tests
|
||||||
in the .js file.
|
in the .js file.
|
||||||
|
|
||||||
7. Start test(s) in the [_node-inspector_][node_inspector] debugger.
|
4. Start test(s) in the [_node-inspector_][node_inspector] debugger.
|
||||||
(Note that the tests can be run without the debugger, but there will probably
|
(The tests can be run without the debugger, but there will probably
|
||||||
be problems with timeouts or reused ledgers).
|
be problems with timeouts or reused ledgers).
|
||||||
1. `node_modules/node-inspector/bin/inspector.js &`
|
1. `node_modules/node-inspector/bin/inspector.js &`
|
||||||
2. `node node_modules/.bin/mocha --debug --debug-brk test/<testfile.js>`
|
2. `node node_modules/.bin/mocha --debug --debug-brk test/<testfile.js>`
|
||||||
3. Browse to http://127.0.0.1:8080/debug?port=5858 in a browser supported
|
3. Browse to http://127.0.0.1:8080/debug?port=5858 in a browser supported
|
||||||
by [_node-inspector_][node_inspector] (i.e. Chrome or Safari).
|
by [_node-inspector_][node_inspector] (i.e. Chrome or Safari).
|
||||||
|
|
||||||
8. To run multiple tests, put a breakpoint in the following function:
|
5. To run multiple tests (not recommended), put a breakpoint in the following function:
|
||||||
* File `testutils.js` -> function `build_teardown()` -> nested function
|
* File `testutils.js` -> function `build_teardown()` -> nested function
|
||||||
`teardown()` -> nested series function `stop_server()`.
|
`teardown()` -> nested series function `stop_server()`.
|
||||||
* When this breakpoint is hit, stop and restart `rippled`.
|
* When this breakpoint is hit, stop and restart `rippled`.
|
||||||
|
|
||||||
9. Use the [_node-inspector UI_][node_inspector_ui] to step through and run
|
6. Use the [_node-inspector UI_][node_inspector_ui] to step through and run
|
||||||
the test(s) until control is handed off to `rippled`. When the request is
|
the test(s) until control is handed off to `rippled`. When the request is
|
||||||
finished control will be handed back to node-inspector, which may or may not
|
finished control will be handed back to node-inspector, which may or may not
|
||||||
stop depending on which breakpoints are set.
|
stop depending on which breakpoints are set.
|
||||||
|
|
||||||
### After debugging
|
### After debugging using configuration files.
|
||||||
|
|
||||||
|
With the command line `--noserver` flag, this step is unnecessary.
|
||||||
|
|
||||||
1. To return to the default behavior, edit `test/config.js` and change the
|
1. To return to the default behavior, edit `test/config.js` and change the
|
||||||
default server back to its original value: `exports.server_default = "alpha";`.
|
default server back to its original value: `exports.server_default = "alpha";`.
|
||||||
|
|||||||
@@ -88,19 +88,6 @@ Server.prototype._serverSpawnSync = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var rippledpath = this.config.rippled_path;
|
var rippledpath = this.config.rippled_path;
|
||||||
// Override the config with command line if provided
|
|
||||||
if (process.env["npm_config_rippled"]) {
|
|
||||||
rippledpath = path.resolve(process.cwd(),
|
|
||||||
process.env["npm_config_rippled"]);
|
|
||||||
} else {
|
|
||||||
for (var i = process.argv.length-1; i >= 0; --i) {
|
|
||||||
arg = process.argv[i].split("=", 2);
|
|
||||||
if (arg.length === 2 && arg[0] === "--rippled") {
|
|
||||||
rippledpath = path.resolve(process.cwd(), arg[1]);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
assert(rippledpath, "rippled_path not provided");
|
assert(rippledpath, "rippled_path not provided");
|
||||||
|
|
||||||
var args = [
|
var args = [
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ var Amount = require('ripple-lib').Amount;
|
|||||||
var Remote = require('ripple-lib').Remote;
|
var Remote = require('ripple-lib').Remote;
|
||||||
var Transaction = require('ripple-lib').Transaction;
|
var Transaction = require('ripple-lib').Transaction;
|
||||||
var Server = require('./server').Server;
|
var Server = require('./server').Server;
|
||||||
|
var path = require("path");
|
||||||
var server = { };
|
var server = { };
|
||||||
|
|
||||||
function get_config() {
|
function get_config() {
|
||||||
@@ -28,7 +29,35 @@ get_server_config =
|
|||||||
function(config, host) {
|
function(config, host) {
|
||||||
config = config || init_config();
|
config = config || init_config();
|
||||||
host = host || config.server_default;
|
host = host || config.server_default;
|
||||||
return extend({}, config.default_server_config, config.servers[host]);
|
// Override the config with the command line if provided.
|
||||||
|
var override = {};
|
||||||
|
// --noserver -> no_server
|
||||||
|
if (process.env["npm_config_noserver"]) {
|
||||||
|
override["no_server"] = true;
|
||||||
|
} else {
|
||||||
|
override["no_server"] = process.argv.indexOf("--noserver") > -1;
|
||||||
|
}
|
||||||
|
// --rippled -> rippled_path
|
||||||
|
var index = -1;
|
||||||
|
if (process.env["npm_config_rippled"]) {
|
||||||
|
override["rippled_path"] = path.resolve(process.cwd(),
|
||||||
|
process.env["npm_config_rippled"]);
|
||||||
|
} else if ((index = process.argv.indexOf("--rippled")) > -1) {
|
||||||
|
if (index < process.argv.length) {
|
||||||
|
override["rippled_path"] = path.resolve(process.cwd(),
|
||||||
|
process.argv[index + 1]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var i = process.argv.length-1; i >= 0; --i) {
|
||||||
|
var arg = process.argv[i].split("=", 2);
|
||||||
|
if (arg.length === 2 && arg[0] === "--rippled") {
|
||||||
|
override["rippled_path"] = path.resolve(process.cwd(), arg[1]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return extend({}, config.default_server_config, config.servers[host],
|
||||||
|
override);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepare_tests(tests, fn) {
|
function prepare_tests(tests, fn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user