Fix WiFi helper retry/reset behavior and test API usage#351
Conversation
- Allow `WifiNetworkHelper` to be reset and started again. - Keep reconnect state accurate when IP is lost and restored. - Fix nanoFramework-nullability issue in the WiFi helper. - Update WiFi tests to the v3 API. - Refresh WiFi README guidance for retry/reconfiguration.
1d9a38a to
6352542
Compare
|
Warning Review limit reached
More reviews will be available in 44 minutes and 17 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Repository: nanoframework/coderabbit/.coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR adds a public ChangesWiFi Helper Retry and Reset Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
|
| Previously published | This build | |
|---|---|---|
| Native version | 100.0.6.5 |
100.0.6.6 |
| Checksum | 0x030E2768 |
0xEE721CDA |
👉 Tracking issue: nanoframework/Home#1775
The issue contains a link to the stubs artifact from this build and instructions for GitHub Copilot to perform the update.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Tests/NFUnitTestWifiConnection/ConnectToWifiWithCredentialsScanTests.cs (1)
77-87:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAdd a trailing
Reset()to avoid leaking helper state into later tests.The first
SetupNetworkHelper()succeeds and sets_helperInstanciated = truebefore the second call throws. SinceReset()is not called after theThrowsExceptionblock, the static guard stays set, which can cause subsequent event-based tests (running on real hardware) to throw unexpectedly. The newTestSingleUsageEventBasedalready adds this cleanup; mirror it here for consistent test isolation.🧹 Proposed cleanup
// call twice, it's a NO NO and should throw an exception WifiNetworkHelper.SetupNetworkHelper(); }); + + WifiNetworkHelper.Reset(); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@Tests/NFUnitTestWifiConnection/ConnectToWifiWithCredentialsScanTests.cs` around lines 77 - 87, TestSingleUsage leaves WifiNetworkHelper's static guard set because the first call to WifiNetworkHelper.SetupNetworkHelper() sets _helperInstanciated = true before the second call throws; add a trailing cleanup call to WifiNetworkHelper.Reset() after the Assert.ThrowsException block in TestSingleUsage so the static state is cleared and does not leak into subsequent tests (mirror the cleanup used in TestSingleUsageEventBased).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Line 177: Remove the stray empty Markdown heading introduced as "## " in
README.md (the blank second-level header at line where an empty section
appears); either delete that line entirely or replace it with an appropriate
section title so the document renders correctly and navigation is not broken.
In `@System.Device.Wifi/NetworkHelper/WifiNetworkHelper.cs`:
- Line 47: The XML doc cref currently points to a non-existent parameterless
SetupNetworkHelper(); update the cref to reference one of the actual overload
signatures that exist in this class (for example SetupNetworkHelper(WifiConfig
config) or SetupNetworkHelper(Action onConnected) — use the exact parameter type
list used in the implementation) so the XML reference resolves; apply the same
change to both occurrences that mention SetupNetworkHelper().
- Line 540: Extract the "ensure connected to the target SSID" block out of
SetupHelper into a private helper method (e.g., TryPrepareWifiConnection) that
accepts NetworkInterface[] nis and returns bool indicating whether caller should
proceed to connect; inside it check _ssid/_password emptiness, iterate
Wireless80211 NetworkInterface entries, use
Wireless80211Configuration.GetAllWireless80211Configurations()[ni.SpecificConfigId]
to compare wc.Ssid to _ssid and return false if already configured, otherwise
call _wifi.Disconnect(), call StoreWifiConfiguration(ni) for the first matching
wireless interface and return true; update SetupHelper to call bool
connectToWifi = TryPrepareWifiConnection(nis) and use that flag to flatten the
existing if/else nesting while preserving existing behavior and side-effects.
---
Outside diff comments:
In `@Tests/NFUnitTestWifiConnection/ConnectToWifiWithCredentialsScanTests.cs`:
- Around line 77-87: TestSingleUsage leaves WifiNetworkHelper's static guard set
because the first call to WifiNetworkHelper.SetupNetworkHelper() sets
_helperInstanciated = true before the second call throws; add a trailing cleanup
call to WifiNetworkHelper.Reset() after the Assert.ThrowsException block in
TestSingleUsage so the static state is cleared and does not leak into subsequent
tests (mirror the cleanup used in TestSingleUsageEventBased).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: nanoframework/coderabbit/.coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e48e49fa-82bd-4579-9600-60d14705d3b9
📒 Files selected for processing (7)
README.mdSystem.Device.Wifi/NetworkHelper/WifiNetworkHelper.csSystem.Device.Wifi/Properties/AssemblyInfo.csTests/NFUnitTestWifiConnection/ConnectToWifiFixIPAddressTests.csTests/NFUnitTestWifiConnection/ConnectToWifiWithCredentialsScanTests.csTests/NFUnitTestWifiConnection/ConnectToWifiWithCredentialsTests.csTests/NFUnitTestWifiConnection/ConnectToWifiWithoutCredentialsTests.cs
Description
WifiNetworkHelperto be reset and started again.Motivation and Context
How Has This Been Tested?
Screenshots
Types of changes
Checklist: