Skip to content

Commit

Permalink
FAB-1117 NodeSDK event hub connect
Browse files Browse the repository at this point in the history
Allow the connect to have a start block and
also be able to take a new peer target.
Add the reconnect to allow the application
to restart the connectioin and request
the start block to be the last block this
event hub has seen.
Restructure the testing to isolate all parts
to avoid conflicts between the different
tools.

Change-Id: I53bac25dd5c5e295b7cb94898a9a7f504cfd6fd2
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Feb 12, 2019
1 parent 9ea9c26 commit 4b6b3b1
Show file tree
Hide file tree
Showing 8 changed files with 1,072 additions and 209 deletions.
42 changes: 29 additions & 13 deletions build/tasks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,23 @@ gulp.task('compile', shell.task([
// - Use nyc instead of gulp-istanbul to generate coverage report
// - Cannot use gulp-istabul because it throws "unexpected identifier" for async/await functions

// Main test to run all tests
gulp.task('test', shell.task('npx nyc gulp run-test'));

// Test to run all unit tests
gulp.task('test-headless', shell.task('npx nyc gulp run-test-headless'));
gulp.task('test-headless', shell.task('npx nyc --check-coverage --lines 50 --statements 50 --functions 50 --branches 50 gulp run-test-headless'));

// Test to run only tape integration test
gulp.task('test-integration', shell.task('npx nyc --check-coverage --lines 50 --statements 50 --functions 50 --branches 50 gulp run-test-integration'));

// Test to run only tape integration test
gulp.task('test-cucumber', shell.task('npx nyc gulp run-test-cucumber'));

// Test to run only logger test
gulp.task('test-logger', shell.task('npx nyc gulp run-test-logger'));

// -------------------------------------------------------------------------

// Only run Mocha unit tests
gulp.task('test-mocha', shell.task('npx nyc gulp run-test-mocha'));

// Only run scenario tests
gulp.task('test-cucumber', shell.task('npx nyc npm run test:cucumber'));

// Definition of Mocha (unit) test suites
gulp.task('run-test-mocha', (done) => {
const tasks = ['mocha-fabric-ca-client', 'mocha-fabric-client', 'mocha-fabric-network'];
Expand Down Expand Up @@ -164,9 +169,6 @@ gulp.task('mocha-fabric-network',
}
);

// Test to run all unit tests
gulp.task('test-tape', shell.task('npx nyc gulp run-tape-unit'));

// Definition of Cucumber (scenario) test suite
gulp.task('run-test-cucumber', shell.task(
'export HFC_LOGGING=""; npm run test:cucumber'
Expand All @@ -175,13 +177,27 @@ gulp.task('run-test-cucumber', shell.task(
// Main test method to run all test suites
// - lint, unit first, then FV, then scenario
gulp.task('run-test', (done) => {
const tasks = ['clean-up', 'docker-clean', 'pre-test', 'ca', 'compile', 'lint', 'run-test-mocha', 'run-tape-unit', 'run-tape-e2e', 'run-logger-unit', 'docker-clean', 'run-test-cucumber'];
const tasks = ['clean-up', 'docker-clean', 'pre-test', 'ca', 'compile', 'lint', 'run-test-mocha', 'run-tape-unit', 'run-tape-e2e', 'run-test-logger', 'docker-clean', 'run-test-cucumber'];
runSequence(...tasks, done);
});

// Main test method to run all test suites
// - lint, unit first, then FV, then scenario
gulp.task('run-test-integration', (done) => {
const tasks = ['clean-up', 'docker-clean', 'pre-test', 'ca', 'lint', 'run-tape-e2e'];
runSequence(...tasks, done);
});

// Main test method to run all test suites
// - lint, unit first, then FV, then scenario
gulp.task('test-cucumber', (done) => {
const tasks = ['clean-up', 'docker-clean', 'run-test-cucumber'];
runSequence(...tasks, done);
});

// Run all non-integration tests
gulp.task('run-test-headless', (done) => {
const tasks = ['clean-up', 'pre-test', 'ca', 'lint', 'run-test-mocha', 'run-tape-unit', 'run-logger-unit'];
const tasks = ['clean-up', 'pre-test', 'ca', 'lint', 'compile', 'run-test-mocha', 'run-tape-unit'];
runSequence(...tasks, done);
});

Expand All @@ -203,7 +219,7 @@ gulp.task('run-tape-unit',
});

// Run logger in isolation
gulp.task('run-logger-unit',
gulp.task('run-test-logger',
() => {
// this is needed to avoid a problem in tape-promise with adding
// too many listeners to the "unhandledRejection" event
Expand Down
15 changes: 10 additions & 5 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,14 +949,19 @@ const Channel = class {
* This method will create a new ChannelEventHub and not save a reference.
* Use the {getChannelEventHub} to reuse a ChannelEventHub.
*
* @param {Peer | string} peer A Peer instance or the name of a peer that has
* been assigned to the channel.
* @param {Peer | string} peer Optional. A Peer instance or the name of a
* peer that has been assigned to the channel. If not provided the
* ChannelEventHub must be connected with a "target" peer.
* @returns {ChannelEventHub} The ChannelEventHub instance
*/
newChannelEventHub(peer) {
// Will always return one or throw
const peers = this._getTargets(peer, Constants.NetworkConfig.EVENT_SOURCE_ROLE, true);
const channel_event_hub = new ChannelEventHub(this, peers[0]);
let _peer = null;
if (peer) {
const peers = this._getTargets(peer, Constants.NetworkConfig.EVENT_SOURCE_ROLE, true);
_peer = peers[0];
}
const channel_event_hub = new ChannelEventHub(this, _peer);

return channel_event_hub;
}

Expand Down
Loading

0 comments on commit 4b6b3b1

Please sign in to comment.