Skip to content
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

Ocpp: cache and re-use initial status (3rd attempt) #16908

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
wip
  • Loading branch information
andig committed Oct 28, 2024
commit 26e3d2a8b12f75940c333be6c67b07effe6c344a
32 changes: 1 addition & 31 deletions charger/ocpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package charger

import (
"errors"
"fmt"
"sync/atomic"
"testing"
"time"

Expand All @@ -29,54 +27,26 @@ const (
ocppTestConnectTimeout = 10 * time.Second
)

type ocppLogger struct {
suite *ocppTestSuite
}

func (l *ocppLogger) print(s string) {
if !l.suite.done.Load() {
l.suite.T().Log((time.Now().Format(time.DateTime)), s)
}
}

func (l *ocppLogger) Debug(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Debugf(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}
func (l *ocppLogger) Info(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Infof(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}
func (l *ocppLogger) Error(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Errorf(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}

func TestOcpp(t *testing.T) {
suite.Run(t, new(ocppTestSuite))
}

type ocppTestSuite struct {
suite.Suite
clock *clock.Mock
done atomic.Bool
}

func (suite *ocppTestSuite) SetupTest() {
ocpp.Timeout = 5 * time.Second
ocppj.SetLogger(new(ocppLogger))

// setup cs so we can overwrite logger afterwards
_ = ocpp.Instance()
ocppj.SetLogger(&ocppLogger{suite})

suite.clock = clock.NewMock()
suite.NotNil(ocpp.Instance())
}

func (suite *ocppTestSuite) TeardownTest() {
suite.done.Store(true)
}

func (suite *ocppTestSuite) startChargePoint(id string, connectorId int) (ocpp16.ChargePoint, *ocppj.Client) {
// set a handler for all callback functions
handler := &ChargePointHandler{
Expand Down
25 changes: 25 additions & 0 deletions charger/ocpp_test_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package charger

import (
"fmt"
"time"
)

type ocppLogger struct{}

func (l *ocppLogger) print(s string) {
fmt.Println(time.Now().Format(time.DateTime), s)
}

func (l *ocppLogger) Debug(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Debugf(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}
func (l *ocppLogger) Info(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Infof(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}
func (l *ocppLogger) Error(args ...interface{}) { l.print(fmt.Sprint(args...)) }
func (l *ocppLogger) Errorf(format string, args ...interface{}) {
l.print(fmt.Sprintf(format, args...))
}
Loading