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

More multi message tests for WebSockets #2184

Merged
merged 7 commits into from
Oct 19, 2021
Merged

More multi message tests for WebSockets #2184

merged 7 commits into from
Oct 19, 2021

Conversation

cooliscool
Copy link
Contributor

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:

  1. send_receive_multiple_ws
    send and receive messages 'test1', 'test2', 'test3' in sequence then close.
  2. send_receive_multiple_wss
    send and receive messages 'test1', and then 'test2', then close on a wss connection
  3. send_receive_text_binary
    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 of ws_msgs_sent and ws_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 param count could be useful later.

@github-actions github-actions bot requested review from imiric and yorugac October 13, 2021 16:59
@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2021

Codecov Report

Merging #2184 (4cffcbe) into master (42f2e60) will increase coverage by 0.03%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
ubuntu 72.68% <71.42%> (+0.03%) ⬆️
windows 72.39% <71.42%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cmd/login_cloud.go 0.00% <0.00%> (ø)
cmd/login_influxdb.go 0.00% <0.00%> (ø)
cmd/ui.go 20.61% <0.00%> (ø)
js/compiler/compiler.go 55.00% <ø> (ø)
lib/execution_segment.go 92.73% <ø> (ø)
lib/executor/ramping_vus.go 94.66% <ø> (ø)
lib/metrics/metrics.go 100.00% <ø> (ø)
ui/form_fields.go 45.71% <0.00%> (ø)
js/modules/k6/ws/ws.go 83.51% <100.00%> (+0.35%) ⬆️
output/csv/config.go 74.00% <100.00%> (+4.23%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7a1ba1...4cffcbe. Read the comment docs.

Copy link
Contributor

@imiric imiric left a 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.

js/modules/k6/ws/ws_test.go Outdated Show resolved Hide resolved
@cooliscool cooliscool requested a review from imiric October 14, 2021 13:08
imiric
imiric previously approved these changes Oct 15, 2021
Copy link
Contributor

@imiric imiric left a 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.

@imiric imiric linked an issue Oct 15, 2021 that may be closed by this pull request
Copy link
Contributor

@yorugac yorugac left a 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.

@cooliscool cooliscool closed this Oct 15, 2021
@cooliscool cooliscool reopened this Oct 15, 2021
@github-actions github-actions bot requested review from inancgumus and na-- October 15, 2021 13:25
@cooliscool
Copy link
Contributor Author

sorry. closed this by mistake.

let me summarise the suggested changes here :

  1. replace instances of assertMetricEmitted() with assertMetricEmittedCount() and count = 1 to reduce the no. of helper functions.

  2. changing the ws-echo HTTPMultiBin handler to support multiple messages. instead of using a test specific handler. the gotcha here would be that existing tests depending on ws-echo shouldn't break.

Its doable without making huge changes in the existing tests i believe.

@imiric
Copy link
Contributor

imiric commented Oct 15, 2021

@cooliscool Don't worry about the HTTPMultiBin change, it's probably better that this uses an isolated handler. And we can move it later if we need it elsewhere.

@imiric imiric removed request for inancgumus and na-- October 15, 2021 13:45
Copy link
Member

@inancgumus inancgumus left a 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.

assert.True(t, ok)
if surl == url {
if sample.Metric.Name == metricName {
actualCount++
Copy link
Member

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.

Copy link
Contributor Author

@cooliscool cooliscool Oct 19, 2021

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++
	}
}

@inancgumus

socket.send(msg1)
})
socket.on("message", function (data){
if (data == msg1){
Copy link
Member

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.

});

if (!thirdMsgRecd) {
throw new Error ("third test message was not received!");
Copy link
Member

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
Copy link
Member

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?

js/modules/k6/ws/ws_test.go Outdated Show resolved Hide resolved
@@ -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) {
Copy link
Member

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.

@yorugac
Copy link
Contributor

yorugac commented Oct 15, 2021

1. replace instances of `assertMetricEmitted()` with `assertMetricEmittedCount()` and count = 1 to reduce the no. of helper functions.

@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 👍

Copy link
Member

@inancgumus inancgumus left a 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. 🎉

Copy link
Contributor

@yorugac yorugac left a 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 🙂

@yorugac yorugac merged commit aab12d5 into grafana:master Oct 19, 2021
@na-- na-- added this to the v0.35.0 milestone Oct 19, 2021
@cooliscool
Copy link
Contributor Author

@imiric @inancgumus @yorugac thanks for the review. ♥

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.

Create multi-message WebSockets test
6 participants