OCPP: guard RemoteStartTransaction#30954
Open
premultiply wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="charger/ocpp/connector_test.go" line_range="237-249" />
<code_context>
+ preparing(time.Second)
+ suite.True(suite.conn.remoteStarted, "guard must stay set on repeated Preparing")
+
+ // leaving Preparing (e.g. cable unplugged) ends the auth cycle
+ _, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{
+ ConnectorId: 1,
+ Status: core.ChargePointStatusAvailable,
+ ErrorCode: core.NoError,
+ Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)),
+ })
+ suite.NoError(err)
+ suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing")
+
+ // next Preparing re-arms a fresh RemoteStartTransaction
</code_context>
<issue_to_address>
**suggestion (testing):** Add coverage for other non-Preparing states that should also reset the RemoteStart guard
The production change resets `remoteStarted` on any transition away from `Preparing`, not only when going to `Available`. To fully exercise this behavior, please add cases that transition from `Preparing` to other statuses (e.g. `Charging`, `SuspendedEV`, `SuspendedEVSE`, or an error state) and assert that the guard resets in each case, possibly via a small table-driven test.
```suggestion
// leaving Preparing (e.g. cable unplugged) ends the auth cycle
_, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{
ConnectorId: 1,
Status: core.ChargePointStatusAvailable,
ErrorCode: core.NoError,
Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)),
})
suite.NoError(err)
suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing")
// leaving Preparing for any other status must also end the auth cycle and reset the guard
transitions := []struct {
name string
status core.ChargePointStatus
code core.ChargePointErrorCode
}{
{"Charging", core.ChargePointStatusCharging, core.NoError},
{"SuspendedEV", core.ChargePointStatusSuspendedEV, core.NoError},
{"SuspendedEVSE", core.ChargePointStatusSuspendedEVSE, core.NoError},
{"FaultedWithError", core.ChargePointStatusFaulted, core.InternalError},
}
for _, tt := range transitions {
// re-arm from Preparing
preparing(0)
suite.True(suite.conn.remoteStarted, "guard must be set before transitioning to %s", tt.name)
_, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{
ConnectorId: 1,
Status: tt.status,
ErrorCode: tt.code,
Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)),
})
suite.NoError(err)
suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing to %s", tt.name)
}
// next Preparing re-arms a fresh RemoteStartTransaction
preparing(3 * time.Second)
suite.True(suite.conn.remoteStarted, "guard must re-arm on the next auth cycle")
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+237
to
+249
| // leaving Preparing (e.g. cable unplugged) ends the auth cycle | ||
| _, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{ | ||
| ConnectorId: 1, | ||
| Status: core.ChargePointStatusAvailable, | ||
| ErrorCode: core.NoError, | ||
| Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)), | ||
| }) | ||
| suite.NoError(err) | ||
| suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing") | ||
|
|
||
| // next Preparing re-arms a fresh RemoteStartTransaction | ||
| preparing(3 * time.Second) | ||
| suite.True(suite.conn.remoteStarted, "guard must re-arm on the next auth cycle") |
Contributor
There was a problem hiding this comment.
suggestion (testing): Add coverage for other non-Preparing states that should also reset the RemoteStart guard
The production change resets remoteStarted on any transition away from Preparing, not only when going to Available. To fully exercise this behavior, please add cases that transition from Preparing to other statuses (e.g. Charging, SuspendedEV, SuspendedEVSE, or an error state) and assert that the guard resets in each case, possibly via a small table-driven test.
Suggested change
| // leaving Preparing (e.g. cable unplugged) ends the auth cycle | |
| _, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{ | |
| ConnectorId: 1, | |
| Status: core.ChargePointStatusAvailable, | |
| ErrorCode: core.NoError, | |
| Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)), | |
| }) | |
| suite.NoError(err) | |
| suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing") | |
| // next Preparing re-arms a fresh RemoteStartTransaction | |
| preparing(3 * time.Second) | |
| suite.True(suite.conn.remoteStarted, "guard must re-arm on the next auth cycle") | |
| // leaving Preparing (e.g. cable unplugged) ends the auth cycle | |
| _, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{ | |
| ConnectorId: 1, | |
| Status: core.ChargePointStatusAvailable, | |
| ErrorCode: core.NoError, | |
| Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)), | |
| }) | |
| suite.NoError(err) | |
| suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing") | |
| // leaving Preparing for any other status must also end the auth cycle and reset the guard | |
| transitions := []struct { | |
| name string | |
| status core.ChargePointStatus | |
| code core.ChargePointErrorCode | |
| }{ | |
| {"Charging", core.ChargePointStatusCharging, core.NoError}, | |
| {"SuspendedEV", core.ChargePointStatusSuspendedEV, core.NoError}, | |
| {"SuspendedEVSE", core.ChargePointStatusSuspendedEVSE, core.NoError}, | |
| {"FaultedWithError", core.ChargePointStatusFaulted, core.InternalError}, | |
| } | |
| for _, tt := range transitions { | |
| // re-arm from Preparing | |
| preparing(0) | |
| suite.True(suite.conn.remoteStarted, "guard must be set before transitioning to %s", tt.name) | |
| _, err := suite.conn.OnStatusNotification(&core.StatusNotificationRequest{ | |
| ConnectorId: 1, | |
| Status: tt.status, | |
| ErrorCode: tt.code, | |
| Timestamp: types.NewDateTime(suite.clock.Now().Add(2 * time.Second)), | |
| }) | |
| suite.NoError(err) | |
| suite.False(suite.conn.remoteStarted, "guard must reset when leaving Preparing to %s", tt.name) | |
| } | |
| // next Preparing re-arms a fresh RemoteStartTransaction | |
| preparing(3 * time.Second) | |
| suite.True(suite.conn.remoteStarted, "guard must re-arm on the next auth cycle") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
May fix #30943