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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

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 61.63522% with 61 lines in your changes missing coverage. Please review.

Project coverage is 41.23%. Comparing base (a164070) to head (8496af3).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
engine/access/rest/websockets/controller.go 70.00% 12 Missing and 6 partials ⚠️
engine/access/rest/websockets/connection.go 0.00% 12 Missing ⚠️
...ccess/rest/websockets/mock/websocket_connection.go 78.57% 4 Missing and 5 partials ⚠️
engine/access/rest/websockets/handler.go 0.00% 7 Missing ⚠️
...est/websockets/data_provider/mock/data_provider.go 58.33% 2 Missing and 3 partials ⚠️
...cess/rest/websockets/data_provider/mock/factory.go 73.68% 2 Missing and 3 partials ⚠️
engine/access/rest/router/router.go 0.00% 2 Missing ⚠️
...ine/access/rest/websockets/data_provider/blocks.go 0.00% 2 Missing ⚠️
...ne/access/rest/websockets/data_provider/factory.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6762      +/-   ##
==========================================
+ Coverage   39.71%   41.23%   +1.51%     
==========================================
  Files        1332     2064     +732     
  Lines      123050   182805   +59755     
==========================================
+ Hits        48875    75383   +26508     
- Misses      69986   101096   +31110     
- Partials     4189     6326    +2137     
Flag Coverage Δ
unittests 41.23% <61.63%> (+1.51%) ⬆️

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!

Close() error
}

type GorillaWebsocketConnection struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add godoc here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like it's redundant in this case. The intention is pretty clear. What do you think?

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
4 participants