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

Configurable socket namespace per emit action #125

Closed
wants to merge 6 commits into from

Conversation

menzow
Copy link
Contributor

@menzow menzow commented Nov 30, 2016

This change allows socket.IO namespaces to be configured by adding a namespace attribute to the emit actions.

More info: #124

@hassy
Copy link
Member

hassy commented Dec 1, 2016

Can you add a test case for the new functionality please?

An existing socket.io test seems to be broken as well.

@menzow
Copy link
Contributor Author

menzow commented Dec 1, 2016

Hey @hassy,

Thanks for your feedback, I fixed the failing test.
Where do you want me to add the additional tests?

I guess a new test scenario should be added here: artillery-core/test/scripts called namespaces_socketio.json.

Any other tests that need to be created?

@hassy
Copy link
Member

hassy commented Dec 1, 2016

@menzow Cool, cheers. Yeah a simple script using namespaces will do, perhaps using two different namespaces and verifying the messages that come back. The test Socket.io servers[1] will need to be updated to send something back (same value) on different namespaces, and perhaps to print the number of clients/messages in different namespaces as well to help debugging.

  1. https://github.com/shoreditch-ops/artillery-core/blob/master/test/targets/simple_socketio.js and https://github.com/shoreditch-ops/artillery-core/blob/master/test/targets/express_socketio.js

@menzow
Copy link
Contributor Author

menzow commented Dec 3, 2016

Hey @hassy,

Added tests for namespaces and fixed the errors. Please review it.

Edit: I did add the namespace tests to the simple_socketio.js server instance. Not sure what the guidelines are on that. I could create a separate server instance that handles the namespace tests

@hassy
Copy link
Member

hassy commented Dec 5, 2016

Cool, thanks @menzow

// Only process emit requests; delegate the rest to the HTTP engine (or think utility)
if (requestSpec.think) {
return engineUtil.createThink(requestSpec, _.get(self.config, 'defaults.think', {}));
Copy link
Member

Choose a reason for hiding this comment

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

We need to preserve the second argument to createThink, otherwise default think settings won't be applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I've put it back.

@@ -118,10 +118,10 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
return engineUtil.createLoopWithCount(requestSpec.count || -1, steps);
}

let f = function(context, callback) {
let f = function(context, callback, socketio) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a particular reason we are passing socketio as an extra argument here, rather than keeping it attached to context? That function's signature should really follow that of async#waterfall task functions since that's where f is used. This would avoid us needing to wrap f in preStep as well.

Copy link
Contributor Author

@menzow menzow Dec 8, 2016

Choose a reason for hiding this comment

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

Ah you're right, I overlooked that part. Please see next commit.

@hassy
Copy link
Member

hassy commented Dec 6, 2016

@menzow I added a couple of comments inline. Thank you for your work.

Copy link
Contributor Author

@menzow menzow left a comment

Choose a reason for hiding this comment

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

Processed feedback.

// Only process emit requests; delegate the rest to the HTTP engine (or think utility)
if (requestSpec.think) {
return engineUtil.createThink(requestSpec, _.get(self.config, 'defaults.think', {}));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I've put it back.

@@ -118,10 +118,10 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
return engineUtil.createLoopWithCount(requestSpec.count || -1, steps);
}

let f = function(context, callback) {
let f = function(context, callback, socketio) {
Copy link
Contributor Author

@menzow menzow Dec 8, 2016

Choose a reason for hiding this comment

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

Ah you're right, I overlooked that part. Please see next commit.

…ameter from step:f() function for better compatibility with async#waterfall
if (!(requestSpec.emit && requestSpec.emit.channel)) {
ee.emit('error', 'invalid arguments');
if (!(requestSpec.emit && requestSpec.emit.channel && socketio)) {
return ee.emit('error', 'invalid arguments');
Copy link
Contributor Author

@menzow menzow Dec 8, 2016

Choose a reason for hiding this comment

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

@hassy, I added socketio to be required here either. And I return after the error emit. Continuing execution without these variables seems unnecessary / problematic.

SocketIoEngine.prototype.getSocket = function(namespace, context, cb) {
context.namespaces = context.namespaces || {};
SocketIoEngine.prototype.loadContextSocket = function(namespace, context, cb) {
context.sockets = context.sockets || {};
Copy link
Contributor Author

@menzow menzow Dec 8, 2016

Choose a reason for hiding this comment

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

Renamed context.namespaces to context.sockets. Naming seemed more explanatory.

@@ -118,20 +118,21 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
return engineUtil.createLoopWithCount(requestSpec.count || -1, steps);
}

let f = function(context, callback, socketio) {
let f = function(context, callback) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed socketio parameter.

Socket is now taken from context.sockets[requestSpec.emit.namespace] at line 132.

@@ -180,52 +181,55 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
};

function preStep(context, callback){
Copy link
Contributor Author

@menzow menzow Dec 8, 2016

Choose a reason for hiding this comment

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

preStep behaves as a decorator for function f. It ensures that the socket for the emit namespace is loaded before executing f.

Omitting it would add unnecessary complexity inside the f function. Separation keeps everything a bit more in line with the single responsibility principle. I ensured that the invocation parameters of preStep and f are the same.

@hassy
Copy link
Member

hassy commented Dec 8, 2016

Cool, nice work @menzow 👍

@hassy
Copy link
Member

hassy commented Dec 8, 2016

Would you mind squashing all of your commits here into one? Just one last thing before I merge.

@menzow
Copy link
Contributor Author

menzow commented Dec 8, 2016

Hey @hassy ,
Awesome that it's going to be merged!

Created a new PR #129 with the squashed commits, however I'm not familiar with the technique. Hope that one is correct.

@hassy
Copy link
Member

hassy commented Dec 8, 2016

Cool. You could've done this instead to avoid needing to create a new PR:

# in your fork:
git rebase -i HEAD~6
# change "pick" to "s" in the editor for all commits but the first one, save and exit
# in the next editor window, rewrite the commit message
# then:
git push -f origin master
# that would've updated this PR directly instead

@hassy
Copy link
Member

hassy commented Dec 8, 2016

Merged the other PR. Cheers @menzow

@hassy hassy closed this Dec 8, 2016
@menzow
Copy link
Contributor Author

menzow commented Dec 8, 2016

Thanks for merging! Helps out my test case a lot. I'll add a new topic in the docs explaining how to use namespaces so it may help out other users.

One unrelated question:
Since I already pushed my changes, doesn't squashing the last 6 commits on the same branch mess up the commit history / commit references in github?

@hassy
Copy link
Member

hassy commented Dec 8, 2016

Github keeps all commits, even the ones that have been over-written with a force-push, so it's still possible to see the original discussion, it's just marked as "outdated".

@menzow
Copy link
Contributor Author

menzow commented Dec 8, 2016

@hassy , thanks for the info 😃. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants