-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
OCPP: per-connection BootNotification handshake on reconnect #31192
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
base: master
Are you sure you want to change the base?
Changes from all commits
8161a32
06621e3
8746c2d
5fcaabe
8565082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,3 +239,94 @@ func TestMonitorRebootOnlyOnce(t *testing.T) { | |
| require.Eventually(t, func() bool { return callCount.Load() == 1 }, time.Second, 10*time.Millisecond, | ||
| "setup should be called exactly once") | ||
| } | ||
|
|
||
| func TestTriggeredBootNotificationDoesNotNotifyRebootMonitor(t *testing.T) { | ||
| log := util.NewLogger("test") | ||
| cp := NewChargePoint(log, "test-cp") | ||
| boot := core.BootNotificationRequest{ | ||
| ChargePointModel: "Model", | ||
| ChargePointVendor: "TestVendor", | ||
| FirmwareVersion: "1.0.0", | ||
| } | ||
| // unchanged metadata from a previous connection plus a solicited boot | ||
| cached := boot | ||
| cp.BootNotificationResult = &cached | ||
| cp.bootTriggered = true | ||
|
|
||
| current := boot | ||
| _, err := cp.OnBootNotification(¤t) | ||
| require.NoError(t, err) | ||
| assert.True(t, cp.Connected()) | ||
| assert.False(t, cp.bootTriggered, "flag should be consumed") | ||
| assert.Equal(t, ¤t, cp.BootNotificationResult, "metadata should be refreshed") | ||
|
|
||
| select { | ||
| case req := <-cp.bootNotificationRequestC: | ||
| t.Fatalf("unchanged triggered BootNotification should not notify reboot monitor, got %s", req.ChargePointModel) | ||
| default: | ||
| } | ||
| } | ||
|
|
||
| // TestTriggeredBootNotificationWithChangedIdentityNotifiesRebootMonitor covers a | ||
| // charger that actually restarted (e.g. firmware update) but whose boot arrives as | ||
| // a solicited one: the changed content must still trigger a setup re-initialization. | ||
| func TestTriggeredBootNotificationWithChangedIdentityNotifiesRebootMonitor(t *testing.T) { | ||
| log := util.NewLogger("test") | ||
| cp := NewChargePoint(log, "test-cp") | ||
| cp.BootNotificationResult = &core.BootNotificationRequest{ | ||
| ChargePointModel: "Model", | ||
| ChargePointVendor: "TestVendor", | ||
| FirmwareVersion: "1.0.0", | ||
| } | ||
| cp.bootTriggered = true | ||
|
|
||
| _, err := cp.OnBootNotification(&core.BootNotificationRequest{ | ||
| ChargePointModel: "Model", | ||
| ChargePointVendor: "TestVendor", | ||
| FirmwareVersion: "1.1.0", // updated firmware | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.True(t, cp.Connected()) | ||
|
|
||
| select { | ||
| case req := <-cp.bootNotificationRequestC: | ||
| assert.Equal(t, "1.1.0", req.FirmwareVersion) | ||
| default: | ||
|
premultiply marked this conversation as resolved.
|
||
| t.Fatal("changed triggered BootNotification should notify reboot monitor") | ||
| } | ||
| } | ||
|
|
||
| // TestBootTimeoutClearsTriggeredFlag ensures a solicited BootNotification that never | ||
| // arrives does not leak the bootTriggered flag past the connection: the boot timeout | ||
| // must clear it so the next connection's spontaneous boot is treated as a reboot. | ||
| func TestBootTimeoutClearsTriggeredFlag(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (testing): Avoid using a 1-hour timer in the test to reduce flakiness and stray goroutines In |
||
| log := util.NewLogger("test") | ||
| cp := NewChargePoint(log, "test-cp") | ||
| cp.bootTriggered = true | ||
|
|
||
| timer := time.AfterFunc(time.Hour, func() {}) | ||
| cp.bootTimer = timer | ||
| cp.onBootTimeout(timer) | ||
|
|
||
| assert.False(t, cp.bootTriggered, "flag must be cleared on boot timeout") | ||
| assert.True(t, cp.Connected()) | ||
| } | ||
|
|
||
| func TestSpontaneousBootNotificationNotifiesRebootMonitor(t *testing.T) { | ||
| log := util.NewLogger("test") | ||
| cp := NewChargePoint(log, "test-cp") | ||
|
|
||
| _, err := cp.OnBootNotification(&core.BootNotificationRequest{ | ||
| ChargePointModel: "Rebooted", | ||
| ChargePointVendor: "TestVendor", | ||
| }) | ||
| require.NoError(t, err) | ||
| assert.True(t, cp.Connected()) | ||
|
|
||
| select { | ||
| case req := <-cp.bootNotificationRequestC: | ||
| assert.Equal(t, "Rebooted", req.ChargePointModel) | ||
| default: | ||
| t.Fatal("spontaneous BootNotification should notify reboot monitor") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Add a test for the case where a solicited BootNotification is the first-ever boot (no previous metadata)
The updated logic only suppresses reboot notifications when
bootTriggered && prev != nil && *prev == *request. Current tests cover solicited boots with unchanged vs changed cached metadata. Please add a test for a first connection wherebootTriggered == trueandBootNotificationResultisnil, and assert that the reboot-monitor channel receives the request. This will lock in the behavior that first boots always notify the reboot monitor, distinguishing them from reconnects.Suggested implementation:
To integrate this test with the rest of your codebase:
contextandtimeare imported incp_core_test.goif they are not already:import "context"import "time"cp.handleBootNotificationRequest(context.Background(), &boot)with the actual helper/function you use in other tests to feed acore.BootNotificationRequestthrough the charge point logic (e.g.,cp.OnBootNotification,cp.HandleBootNotification, etc.), matching its signature and usage pattern.bootNotificationRequestCis a channel ofcore.BootNotificationRequestrather than pointers, adjust the select-case accordingly (remove the pointer dereference and update the comparisons).time.Secondfor consistency.