Skip to content

Lab 8: Clean Sonar issues and prepare gated build#20

Merged
rsukhaniuk merged 12 commits into
masterfrom
lab/08-gated-build
May 5, 2026
Merged

Lab 8: Clean Sonar issues and prepare gated build#20
rsukhaniuk merged 12 commits into
masterfrom
lab/08-gated-build

Conversation

@rsukhaniuk
Copy link
Copy Markdown
Owner

@rsukhaniuk rsukhaniuk commented May 5, 2026

What's changed

Maintainability / Code Smells

  • fix maintainability issues in EchoTcpServer
    • fill empty while-loop body in Program.cs
    • seal UdpTimedSender
    • add _disposed guard and call GC.SuppressFinalize in Dispose
  • move IUdpClient into the NetSdrClientApp.Networking namespace
  • fix nullable/code smell issues in NetSdrClient, UdpClientWrapper, and TcpClientWrapper
    • declare nullable fields/variables where needed
    • guard nullable _cts in the receive loop
    • remove unused exception variables
    • use Memory<byte> overloads for ReadAsync and WriteAsync
  • fix code smells in NetSdrMessageHelperTests
    • group independent assertions with Assert.EnterMultipleScope
    • replace Count() checks with array length assertions
  • fix assertion issue in StartListeningAsync_ThenStop_DisposesCtsProperly
  • fix NUnit assertion issue in Equals_DifferentType_ReturnsFalse

Reliability Issues

  • fix cancellation token source disposal in Networking
    • dispose _cts before reassignment in TcpClientWrapper
    • dispose _cts before reassignment in UdpClientWrapper
    • dispose _cts before clearing it in Disconnect
  • add Equals override to UdpClientWrapper alongside GetHashCode

Security Hotspot

  • replace MD5 usage in UdpClientWrapper.GetHashCode with HashCode.Combine

Tests

  • add tests for UdpClientWrapper.Equals
  • add tests for UdpClientWrapper.GetHashCode
  • add test for Connect/SendMessage/Disconnect happy path
  • add test for MessageReceived event when server sends data
  • add test for listener loop exception handling when server closes connection

Risk notes

  • UdpClientWrapper equality/hash behavior was updated, so equality-related behavior is covered by new tests
  • cancellation token source disposal was adjusted in networking classes, so connect/disconnect behavior should be checked
  • no protocol-level behavior changes are intended

How to verify

  • Open the Checks tab in this PR
  • Verify that the SonarCloud analysis passes successfully
  • Verify that the Quality Gate passes
  • Verify that all unit tests pass
  • Verify that new-code conditions are satisfied:
    • Bugs/Vulnerabilities = 0
    • Coverage on New Code ≥ 80%
    • Duplications on New Code ≤ 3%
    • no unresolved critical Sonar issues on new code

rsukhaniuk added 12 commits May 5, 2026 20:57
- fill empty while-loop body in Program.cs
- seal UdpTimedSender and add _disposed guard
- call GC.SuppressFinalize in UdpTimedSender.Dispose
- move IUdpClient into NetSdrClientApp.Networking namespace
- dispose _cts before reassignment in TcpClientWrapper (L43)
- dispose _cts before reassignment in UdpClientWrapper (L26)
- add Equals override to UdpClientWrapper alongside GetHashCode
- declare responseTaskSource as nullable (TaskCompletionSource<byte[]>?)
- change SendTcpRequest return type to Task<byte[]?>
- assign null to nullable responseTaskSource on message received
- remove unused ex variable in UdpClientWrapper catch block
- wrap 2 independent Assert blocks in EnterMultipleScope
- replace 2 IEnumerable Count() calls with ToArray() and Has.Length.EqualTo
- declare _cts as nullable
- dispose _cts before nulling in Disconnect
- guard null _cts in while loop condition
- use Memory<byte> overloads for ReadAsync and WriteAsync
- remove unused ex in OperationCanceledException catch
…lientWrapper

- add Connected and Disconnect tests for TcpClientWrapper
- add Equals with different type and StartListeningAsync/StopListening tests for UdpClientWrapper
…erage

- add Connect/SendMessage/Disconnect happy path test
- add MessageReceived event test when server sends data
- add listener loop exception handling test when server closes connection
- replace Is.False with Is.EqualTo(false) in Equals_DifferentType_ReturnsFalse
- add assertion to StartListeningAsync_ThenStop_DisposesCtsProperly
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@rsukhaniuk rsukhaniuk merged commit b3d939e into master May 5, 2026
3 checks passed
@rsukhaniuk
Copy link
Copy Markdown
Owner Author

rsukhaniuk commented May 5, 2026

Lab 8 result

Gated merge was configured for the master branch using GitHub Rulesets.

Configured required checks:

  • Sonar Check
  • SonarCloud Code Analysis

SonarCloud Quality Gate passed successfully.


Active GitHub ruleset for master


Screenshot 2026-05-05 233139

Required status checks configuration


Screenshot 2026-05-05 233207

Latest master branch check status


Screenshot 2026-05-05 232425

SonarCloud New Code Quality Gate result


Screenshot 2026-05-05 232437

SonarCloud Overall Code metrics


Screenshot 2026-05-05 232447

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.

1 participant