-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
More multi message tests for WebSockets #2184
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2184 +/- ##
==========================================
+ Coverage 72.71% 72.75% +0.03%
==========================================
Files 184 184
Lines 14571 14577 +6
==========================================
+ Hits 10596 10605 +9
+ Misses 3333 3330 -3
Partials 642 642
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Thanks for the PR @cooliscool! This LGTM, just noticed a typo in a test that doesn't really change the outcome.
I'm a bit concerned about whether running these tests parallely using same runtime will cause a race condition, for test to fail. (randomly, only if some race succeeds)
Yeah, we can't run the subtests in parallel because of the shared goja.Runtime
, and while the current t.Parallel()
you have in the multi_message
test doesn't do any harm, I would prefer if it was removed to be consistent with the other TestSession
tests. We plan to overhaul the WS module in the future and fixing these tests can be done then.
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.
LGTM, thanks!
I wouldn't be against changing the ws-echo
HTTPMultiBin
handler to support multiple messages, since it's used by at least 3 tests now, but adding it in the test is fine as well.
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.
Thank you! LGTM overall, just one thing that I think makes sense to check. There is now assertMetricEmittedCount()
and assertMetricEmitted()
: would all tests pass if you substitute assertMetricEmitted
with assertMetricEmittedCount
and count = 1
? By brief look it should work just as well and then we won't increase the number of helper functions there.
sorry. closed this by mistake. let me summarise the suggested changes here :
Its doable without making huge changes in the existing tests i believe. |
@cooliscool Don't worry about the |
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.
Nice work, thanks. I have some suggestions.
js/modules/k6/ws/ws_test.go
Outdated
assert.True(t, ok) | ||
if surl == url { | ||
if sample.Metric.Name == metricName { | ||
actualCount++ |
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.
What about doing this like:
if surl != url && sample.Metric.Name != metricName {
continue
}
actualCount++
Imho, our eyes are pretty good at following lines; left-indentation can improve glancing at a piece of code.
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.
wouldn't this be more straightforward?
if surl == url && sample.Metric.Name == metricName {
actualCount++
}
instead of
if surl == url {
if sample.Metric.Name == metricName {
actualCount++
}
}
socket.send(msg1) | ||
}) | ||
socket.on("message", function (data){ | ||
if (data == msg1){ |
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 suggest doing:
socket.on("message", function (data){
-> socket.on("message", function (data) {
The same, also, for the if statements below.
js/modules/k6/ws/ws_test.go
Outdated
}); | ||
|
||
if (!thirdMsgRecd) { | ||
throw new Error ("third test message was not received!"); |
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.
Can you add an error why the third message was not received? So, we can see what to look for on an error.
@@ -88,6 +89,23 @@ func assertMetricEmitted(t *testing.T, metricName string, sampleContainers []sta | |||
assert.True(t, seenMetric, "url %s didn't emit %s", url, metricName) | |||
} | |||
|
|||
func assertMetricEmittedCount(t *testing.T, metricName string, sampleContainers []stats.SampleContainer, url string, count int) { | |||
actualCount := 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.
Can you make this helper function a t.Helper
?
@@ -88,6 +89,23 @@ func assertMetricEmitted(t *testing.T, metricName string, sampleContainers []sta | |||
assert.True(t, seenMetric, "url %s didn't emit %s", url, metricName) | |||
} | |||
|
|||
func assertMetricEmittedCount(t *testing.T, metricName string, sampleContainers []stats.SampleContainer, url string, count int) { |
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 we should make this function accept a struct. It has a lot of parameters, and, IMHO, it makes it hard to follow what's going on when reading the usage of this function inside the tests.
@cooliscool Yes please about this ^^. If it works, then it's best to have a simplified version. And I also agree with @imiric on isolated handler being better at this point 👍 |
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.
LGTM, thanks for your contribution. 🎉
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.
LGTM @cooliscool, thank you 🙂
@imiric @inancgumus @yorugac thanks for the review. ♥ |
In relation to #1152
Explanation :
Didn't modify the ws-echo handler in httpmultibin, instead I extended httpmultibin with a tb.Mux.HandleFunc(...)
Here are the few tests I could add:
send and receive messages 'test1', 'test2', 'test3' in sequence then close.
send and receive messages 'test1', and then 'test2', then close on a wss connection
I thought of this scenario where multiple kind of messages (text and binary) are exchanged over the same socket. So, here's a test that sends a text message and a binary message in sequence.
Other than that, I'm a bit concerned about whether running these tests parallely using same runtime will cause a race condition, for test to fail. (randomly, only if some race succeeds)
And, please let me know if any of these tests needs to be modified, or if you'd like me to add more scenarios, or remove.
ALso, I've added a funtion
assertMetricEmittedCount()
for asserting the count ofws_msgs_sent
andws_msgs_received
collected. I made the number of messages sent '3' in send_receive_multiple_ws because of unparam linter complaining about passing same value to assertMetricEmittedCount() always :/ but that extra paramcount
could be useful later.