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

server: add a way to move connections to a new app version #310

Closed
wants to merge 2 commits into from

Conversation

nechaido
Copy link
Member

@nechaido nechaido commented Dec 6, 2017

No description provided.

const versions = new Map();
index.set(name, versions);
if (instances.length === 1) {
versions.set('1.0.0', instances[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check if app has version and set 1.0.0 only if it doesn't. You discard app version here.

);

if (!application) {
this._handshakeError(errors.ERR_APP_NOT_FOUND);
return;
}

if (!this.requestedVersion) {
this.requestedVersion = semver.major(application.version).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case when there is only one app without version and no version specified upon handshake call this still seems to call semver.major on undefined, or have I missed something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

lib/server.js Outdated
@@ -92,6 +92,19 @@ class Server {
} = prepareApplications(applications));
}

// Update applivation version for each connection.
updateConnections() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe updateConnectionsApi? Just a nit though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like both of them, maybe someone has better ideas @metarhia/jstp-core ?

lib/server.js Outdated
// Update applivation version for each connection.
updateConnections() {
for (const connection of this.clients.values()) {
if (semver.valid(connection.requestedVersion)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add a comment that this function will not update clients who specified direct versions and not version-range upon request in order to make this clearer. Or just comment here like 'ignore clients who requested specific API versions'.

});
});
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also add test that'll test 'must connect to app without version('latest') when client didn't specify version'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lundibundi there is no app without version now, and we already have a test that checks if a user connects to the latest app, if no version was specified.

@@ -55,3 +90,79 @@ test.test('must update API', (test) => {
}
);
});

test.test(
'must not update API on existing connection if no supported version is found',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should clarify test description here and in the tests after this one (probably adding 'version' should be enough), it'll be hard to understand the problem if one of those fails.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lundibundi could you please clarify proposed change?

Copy link
Member

@lundibundi lundibundi Dec 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nechaido We can for example for this test add version to the description as this ''must not update API on existing connection if no supported version is found (connect to @1)" and so with other tests in order to clearly discern them should an error occur.

@belochub
Copy link
Member

Rebase this on master and rename it to correspond to our general naming style, please.

@nechaido nechaido changed the title Update connection app server: add a way to move connections to a new app version Dec 13, 2017
@nechaido nechaido requested a review from lundibundi December 13, 2017 17:25
@@ -17,13 +17,14 @@ const errors = require('./errors');
// of which contains functions by event names. Each method
// has the following signature
// (connection, <0 or more event arguments>)
// version - application version of 'name' application (optional)
// version - application version of 'name' application (optional) if version
// is not provided neither here nor in `name` '1.0.0' will be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a double negative and a missing comma in this sentence which should be fixed and I think it'll be better to start the new sentence from 'if' so that the end result will look like this:

//   version - application version of 'name' application (optional).
//             If a version is provided neither here nor in `name`,
//             '1.0.0' will be used

or

//   version - application version of 'name' application (optional).
//             If a version is not provided either here or in `name`,
//             '1.0.0' will be used

if (!this.version) this.version = version;
if (this.version && !semver.valid(this.version)) {
if (!this.version) this.version = version || '1.0.0';
if (!semver.valid(this.version)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to check the validity of the version after you set its value to '1.0.0', I propose to move the assignment to this.version after if:

    const providedVersion = this.version || version;
    if (providedVersion && !semver.valid(providedVersion)) {
      throw new TypeError('Invalid semver version');
    }
    this.version = providedVersion || '1.0.0';


test.test(
'must not update API on existing connection if no supported version is ' +
'found (connection to @1.0.1)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It says '(connection to @1.0.1)' but you are actually connecting to '1.0.0' on line 158, is this maybe a typo?

}
if (versions.get(application.version)) {
throw new Error(
'Multiple instances of application with the same version'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be better to provide more information in this error, such as application name and version value that is being repeated.

if (!latestApp || semver.gt(application.version, latestApp.version)) {
latestApps.set(application.name, application);
}
if (versions.get(application.version)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use has instead of get in this case.

lib/server.js Outdated
@@ -92,6 +92,22 @@ class Server {
} = prepareApplications(applications));
}

// Update application version for each connection.
// It will update to a newest version in the requested range. If client
// requested version in (1.1) range he will not be updated to (1.2.x). If no
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll be better to specify the first range as (1.1.x) instead of just (1.1) for consistency with the second one.
You should also add a comma after 'range': 'If client requested version in (1.1.x) range, he will...'.

lib/server.js Outdated
// Update application version for each connection.
// It will update to a newest version in the requested range. If client
// requested version in (1.1) range he will not be updated to (1.2.x). If no
// suitable version is found client will use it's previous app version.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a comma and an article here: '...is found, the client will...'.
Also, 'it's' shouldn't have an apostrophe, it is a possessive here.

lib/server.js Outdated
const newApp = this._getApplication(
connection.application.name, connection.requestedVersion
);
connection.application = newApp || connection.application;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, it is better to use if here for readability, because in the case when !newApp is true it comes down to the assignment of the variable to itself, which isn't more clear than just doing

if (newApp) {
  connection.application = newApp;
}

@@ -58,9 +59,15 @@ test.test('must allow to specify version in application name', (test) => {
test.end();
});

test.test('must set version to (1.0.0) if none was provided', (test) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this test have the same description as the one on line 221 in this file, do they test the same thing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to delete a test on line 221. It is deleted now.

@nechaido nechaido requested a review from belochub December 13, 2017 20:37
@nechaido nechaido force-pushed the update-connection-app branch from b214a3a to 99eb3d4 Compare December 14, 2017 15:57
nechaido added a commit that referenced this pull request Dec 19, 2017
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
nechaido added a commit that referenced this pull request Dec 19, 2017
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@nechaido
Copy link
Member Author

Landed in f94b50e and 23b8b18.

@nechaido nechaido closed this Dec 19, 2017
@nechaido nechaido deleted the update-connection-app branch December 19, 2017 16:11
belochub pushed a commit that referenced this pull request Jan 22, 2018
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub pushed a commit that referenced this pull request Jan 22, 2018
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub pushed a commit that referenced this pull request Jan 22, 2018
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
belochub pushed a commit that referenced this pull request Jan 22, 2018
PR-URL: #310
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
@belochub belochub mentioned this pull request Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants