Skip to content

Conversation

@scottinet
Copy link
Contributor

@scottinet scottinet commented Apr 1, 2020

Description

The WebSocket class was abstracting the System.net.WebSockets.ClientWebSocket object by storing it in a dynamic variable.
This was made to allow mocking the ClientWebSocket class (which is final and thus cannot be extended) via duck typing, using a custom IClientWebSocket interface which reproduces parts of the ClientWebSocket API.

Problem is: it seems that the Visual Studio C# linker is smart enough to remove unused functions from compiled applications, but it's unable to detect functions used through dynamic variables.
This made ClientWebSocket functions stripped from applications using our SDK, making it useless with that protocol.

This PR fixes this situation by making our WebSocket protocol implementation use only objects implementing our IClientWebSocket interface, completely removing duck typing.
I added a humble object creating and wrapping ClientWebSocket instances to make that class compatible with our custom interface. That humble object explicitly uses ClientWebSocket functions, forcing the C# linker to keep them in the compiled product.

Mocking is made by injecting a custom mock objecting implementing that interface.

Other changes

  • Fix all warnings (99% of them being missing XML documentation)

How to review

The actual fix is in the Kuzzle/Protocol/WebSocket.cs file (and its unit test counterpart). All other changes are about fixing warnings.

@scottinet scottinet self-assigned this Apr 1, 2020
@scottinet scottinet changed the base branch from 1-stable to 1-dev April 1, 2020 12:46
@scottinet scottinet changed the title Fix missing signatures v1 Fix missing signatures (SDK v1) Apr 1, 2020
Copy link
Member

@rolljee rolljee left a comment

Choose a reason for hiding this comment

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

Approved when CI pass

@codecov
Copy link

codecov bot commented Apr 1, 2020

Codecov Report

Merging #50 into 1-dev will decrease coverage by 0.88%.
The diff coverage is 54.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##            1-dev      #50      +/-   ##
==========================================
- Coverage   83.24%   82.35%   -0.89%     
==========================================
  Files          34       34              
  Lines        1665     1695      +30     
  Branches      200      198       -2     
==========================================
+ Hits         1386     1396      +10     
- Misses        257      277      +20     
  Partials       22       22              
Impacted Files Coverage Δ
Kuzzle/API/Controllers/AdminController.cs 100.00% <ø> (ø)
Kuzzle/API/Controllers/RealtimeController.cs 88.14% <0.00%> (-4.10%) ⬇️
Kuzzle/EventHandler/Events/SubscriptionEvent.cs 100.00% <ø> (ø)
...vents/SubscriptionEvents/SubscriptionClearEvent.cs 100.00% <ø> (ø)
Kuzzle/Exceptions/UnauthorizeException.cs 100.00% <ø> (ø)
Kuzzle/Kuzzle.cs 82.27% <ø> (ø)
Kuzzle/Offline/OfflineManager.cs 70.73% <ø> (ø)
Kuzzle/Offline/Query/QueryReplayer.cs 77.86% <ø> (ø)
Kuzzle/Offline/Query/TimedQuery.cs 29.41% <0.00%> (-0.90%) ⬇️
...zzle/Offline/Subscription/SubscriptionRecoverer.cs 46.15% <0.00%> (ø)
... and 10 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 c7ac194...d158447. Read the comment docs.

@scottinet scottinet merged commit 43d4c28 into 1-dev Apr 1, 2020
@scottinet scottinet deleted the fix-missing-signatures-v1 branch April 1, 2020 15:05
@scottinet scottinet mentioned this pull request Apr 2, 2020
scottinet added a commit that referenced this pull request Apr 2, 2020
# [1.0.1](https://github.com/kuzzleio/sdk-csharp/releases/tag/1.0.1) (2020-04-02)


#### Bug fixes

- [ [#50](#50) ] Fix missing signatures (SDK v1)   ([scottinet](https://github.com/scottinet))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants