Skip to content

Commit

Permalink
Add Stop to CSMS and CentralSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
rbright committed Dec 1, 2023
1 parent d214d7c commit d7cc2f1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ocpp1.6/central_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ func (cs *centralSystem) Start(listenPort int, listenPath string) {
cs.server.Start(listenPort, listenPath)
}

func (cs *centralSystem) Stop() {
cs.server.Stop()
}

func (cs *centralSystem) sendResponse(chargePointId string, confirmation ocpp.Response, err error, requestId string) {
if err != nil {
// Send error response
Expand Down
2 changes: 2 additions & 0 deletions ocpp1.6/v16.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ type CentralSystem interface {

// The function blocks forever, so it is suggested to wrap it in a goroutine, in case other functionality needs to be executed on the main program thread.
Start(listenPort int, listenPath string)
// Stops the central system, clearing all pending requests.
Stop()
// Errors returns a channel for error messages. If it doesn't exist it es created.
Errors() <-chan error
}
Expand Down
5 changes: 5 additions & 0 deletions ocpp1.6_test/ocpp16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ func setupDefaultCentralSystemHandlers(suite *OcppV16TestSuite, coreListener cor
})
suite.centralSystem.SetCoreHandler(coreListener)
suite.mockWsServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(options.startReturnArgument)
suite.mockWsServer.On("Stop").Return()
suite.mockWsServer.On("Write", mock.AnythingOfType("string"), mock.Anything).Return(options.writeReturnArgument).Run(func(args mock.Arguments) {
clientId := args.String(0)
data := args.Get(1)
Expand Down Expand Up @@ -595,6 +596,8 @@ func testUnsupportedRequestFromChargePoint(suite *OcppV16TestSuite, request ocpp
assert.Nil(t, err)
_, ok := <-resultChannel
assert.True(t, ok)
// Stop the central system
suite.centralSystem.Stop()
}

func testUnsupportedRequestFromCentralSystem(suite *OcppV16TestSuite, request ocpp.Request, requestJson string, messageId string) {
Expand Down Expand Up @@ -635,6 +638,8 @@ func testUnsupportedRequestFromCentralSystem(suite *OcppV16TestSuite, request oc
assert.Nil(t, err)
_, ok := <-resultChannel
assert.True(t, ok)
// Stop the central system
suite.centralSystem.Stop()
}

type GenericTestEntry struct {
Expand Down
4 changes: 4 additions & 0 deletions ocpp2.0.1/csms.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,10 @@ func (cs *csms) Start(listenPort int, listenPath string) {
cs.server.Start(listenPort, listenPath)
}

func (cs *csms) Stop() {
cs.server.Stop()
}

func (cs *csms) sendResponse(chargingStationID string, response ocpp.Response, err error, requestId string) {
if err != nil {
// Send error response
Expand Down
2 changes: 2 additions & 0 deletions ocpp2.0.1/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ type CSMS interface {

// The function blocks forever, so it is suggested to wrap it in a goroutine, in case other functionality needs to be executed on the main program thread.
Start(listenPort int, listenPath string)
// Stops the CSMS, clearing all pending requests.
Stop()
// Errors returns a channel for error messages. If it doesn't exist it es created.
Errors() <-chan error
}
Expand Down
5 changes: 5 additions & 0 deletions ocpp2.0.1_test/ocpp2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ func setupDefaultCSMSHandlers(suite *OcppV2TestSuite, options expectedCSMSOption
assert.Equal(t, options.clientId, chargingStation.ID())
})
suite.mockWsServer.On("Start", mock.AnythingOfType("int"), mock.AnythingOfType("string")).Return(options.startReturnArgument)
suite.mockWsServer.On("Stop").Return()
suite.mockWsServer.On("Write", mock.AnythingOfType("string"), mock.Anything).Return(options.writeReturnArgument).Run(func(args mock.Arguments) {
clientId := args.String(0)
data := args.Get(1)
Expand Down Expand Up @@ -1027,6 +1028,8 @@ func testUnsupportedRequestFromChargingStation(suite *OcppV2TestSuite, request o
require.Nil(t, err)
result := <-resultChannel
assert.True(t, result)
// Stop the CSMS
suite.csms.Stop()
}

func testUnsupportedRequestFromCentralSystem(suite *OcppV2TestSuite, request ocpp.Request, requestJson string, messageId string, handlers ...interface{}) {
Expand Down Expand Up @@ -1067,6 +1070,8 @@ func testUnsupportedRequestFromCentralSystem(suite *OcppV2TestSuite, request ocp
assert.Nil(t, err)
_, ok := <-resultChannel
assert.True(t, ok)
// Stop the CSMS
suite.csms.Stop()
}

type GenericTestEntry struct {
Expand Down

0 comments on commit d7cc2f1

Please sign in to comment.