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

[Access] Add unit test for websocket controller #6762

Conversation

illia-malachyn
Copy link
Contributor

@illia-malachyn illia-malachyn commented Nov 26, 2024

Closes: #6635

  • Add unit test for websocket controller
  • Add mock for websocket connection
  • Add mock for data provider
  • Add mock for data provider factory
  • Add mock for websocket connection

The WebSocket Controller interacts with:

  1. Data Provider: Supplies data to the controller.
  2. WebSocket Connection: Handles communication with the client.

To properly test the controller's logic, we mock these interactions. Since the controller runs two parallel routines (reader and writer), the tests also ensure both can shut down cleanly.
A done channel is used in the tests to coordinate this process.

* Add unit test for websocket controller
* Add mock for websocket connection
* Add mock for data provider
* Add mock for data provider factory
* Add mock for websocket connection

The WebSocket Controller interacts with:
1. Data Provider: Supplies data to the controller.
2. WebSocket Connection: Handles communication with the client.

To properly test the controller's logic, we mock these interactions.
Since the controller runs two parallel routines (reader and writer),
the tests also ensure both can shut down cleanly.
A done channel is used in the tests to coordinate this process.
@codecov-commenter
Copy link

codecov-commenter commented Nov 26, 2024

Codecov Report

Attention: Patch coverage is 5.60000% with 236 lines in your changes missing coverage. Please review.

Project coverage is 40.99%. Comparing base (ed6a2c4) to head (2624c64).

Files with missing lines Patch % Lines
storage/mock/iterator.go 0.00% 57 Missing ⚠️
storage/mock/reader.go 0.00% 57 Missing ⚠️
storage/mock/iter_item.go 0.00% 44 Missing ⚠️
storage/mock/writer.go 0.00% 42 Missing ⚠️
storage/mock/reader_batch_writer.go 0.00% 34 Missing ⚠️
engine/access/rest/websockets/controller.go 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6762      +/-   ##
==========================================
- Coverage   42.10%   40.99%   -1.12%     
==========================================
  Files        1524     2100     +576     
  Lines      139324   184862   +45538     
==========================================
+ Hits        58665    75785   +17120     
- Misses      75746   102708   +26962     
- Partials     4913     6369    +1456     
Flag Coverage Δ
unittests 40.99% <5.60%> (-1.12%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@illia-malachyn
Copy link
Contributor Author

illia-malachyn commented Nov 26, 2024

There are no tests for error cases. I think we should add them as part of #6642.
This PR is mostly like a skeleton for tests to enable other team members to write them

@Guitarheroua Guitarheroua changed the title Add unit test for websocket controller [Access] Add unit test for websocket controller Nov 26, 2024
Copy link
Contributor

@Guitarheroua Guitarheroua left a comment

Choose a reason for hiding this comment

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

After first round of review - looks good!

engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller.go Show resolved Hide resolved
engine/access/rest/websockets/controller.go Show resolved Hide resolved
engine/access/rest/websockets/controller_test.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller_test.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@peterargue peterargue left a comment

Choose a reason for hiding this comment

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

added a few small comments. otherwise looks good

return
}
c.logger.Debug().Err(err).Msg("error reading message from client")
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

what type of errors are we allowing here? does it make sense to just close the connection?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will be done later in PR #6798

See diff https://github.com/onflow/flow-go/pull/6798/files#diff-3dc4a79384159575e2c161dbc797a45dea7b38850629edef25b4a9a1cbc2533aR183-R196

It will notify the client, that something went wrong with the incoming message

engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
engine/access/rest/websockets/controller.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Guitarheroua Guitarheroua left a comment

Choose a reason for hiding this comment

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

This one looks good to me!

@peterargue
Copy link
Contributor

@Guitarheroua can you fix these conflicts. after that it's ready to merge

@Guitarheroua Guitarheroua force-pushed the illia-malachyn/6635-tests-for-websocket-controller branch from 84f9c4c to a4e07a3 Compare December 18, 2024 10:26
@Guitarheroua Guitarheroua added this pull request to the merge queue Dec 18, 2024
Merged via the queue into onflow:master with commit 088596f Dec 18, 2024
55 checks passed
@Guitarheroua Guitarheroua deleted the illia-malachyn/6635-tests-for-websocket-controller branch December 18, 2024 16:26
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.

[Access] Implement web socket connection mock for unit testing of web socket controller
5 participants