-
Notifications
You must be signed in to change notification settings - Fork 10
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
Conversation
8b0257a
to
1f67196
Compare
lib/applications.js
Outdated
const versions = new Map(); | ||
index.set(name, versions); | ||
if (instances.length === 1) { | ||
versions.set('1.0.0', instances[0]); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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'.
test/node/api-versions.js
Outdated
}); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
test/node/update-api.js
Outdated
@@ -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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase this on master and rename it to correspond to our general naming style, please. |
lib/applications.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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
lib/applications.js
Outdated
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)) { |
There was a problem hiding this comment.
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/node/update-api.js
Outdated
|
||
test.test( | ||
'must not update API on existing connection if no supported version is ' + | ||
'found (connection to @1.0.1)', |
There was a problem hiding this comment.
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?
lib/applications.js
Outdated
} | ||
if (versions.get(application.version)) { | ||
throw new Error( | ||
'Multiple instances of application with the same version' |
There was a problem hiding this comment.
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.
lib/applications.js
Outdated
if (!latestApp || semver.gt(application.version, latestApp.version)) { | ||
latestApps.set(application.name, application); | ||
} | ||
if (versions.get(application.version)) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
b214a3a
to
99eb3d4
Compare
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
PR-URL: #310 Reviewed-By: Mykola Bilochub <nbelochub@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
No description provided.