Skip to content

Commit

Permalink
Attempt to fix data race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
DerAndereAndi committed Oct 2, 2024
1 parent 51d4e2c commit 9166603
Showing 1 changed file with 67 additions and 46 deletions.
113 changes: 67 additions & 46 deletions usecases/cs/lpc/usecase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func (s *CsLPCSuite) Test_loadControlServerAndLimitId() {
}

func (s *CsLPCSuite) Test_loadControlWriteCB() {
msg := spineapi.Message{}
msg0 := &spineapi.Message{}

s.sut.loadControlWriteCB(&msg)
s.sut.loadControlWriteCB(msg0)
assert.False(s.T(), s.eventCalled)

msg = spineapi.Message{
msg1 := &spineapi.Message{
RequestHeader: &model.HeaderType{
MsgCounter: util.Ptr(model.MsgCounterType(500)),
},
Expand All @@ -43,75 +43,96 @@ func (s *CsLPCSuite) Test_loadControlWriteCB() {
EntityRemote: s.monitoredEntity,
}

msg0 := msg
s.sut.loadControlWriteCB(&msg0)
s.sut.loadControlWriteCB(msg1)
assert.False(s.T(), s.eventCalled)

msg1 := msg
msg1.RequestHeader.MsgCounter = util.Ptr(model.MsgCounterType(501))
msg1.Cmd = model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{},
msg2 := &spineapi.Message{
RequestHeader: &model.HeaderType{
MsgCounter: util.Ptr(model.MsgCounterType(501)),
},
Cmd: model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{},
},
},
DeviceRemote: s.remoteDevice,
EntityRemote: s.monitoredEntity,
}

s.sut.loadControlWriteCB(&msg1)
s.sut.loadControlWriteCB(msg2)
assert.False(s.T(), s.eventCalled)

msg2 := msg
msg2.RequestHeader.MsgCounter = util.Ptr(model.MsgCounterType(502))
msg2.Cmd = model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
{},
msg3 := &spineapi.Message{
RequestHeader: &model.HeaderType{
MsgCounter: util.Ptr(model.MsgCounterType(502)),
},
Cmd: model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
{},
},
},
},
DeviceRemote: s.remoteDevice,
EntityRemote: s.monitoredEntity,
}

s.sut.loadControlWriteCB(&msg2)
s.sut.loadControlWriteCB(msg3)
assert.False(s.T(), s.eventCalled)

msg3 := msg
msg3.RequestHeader.MsgCounter = util.Ptr(model.MsgCounterType(503))
msg3.Cmd = model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
{
LimitId: util.Ptr(model.LoadControlLimitIdType(0)),
IsLimitActive: util.Ptr(true),
Value: model.NewScaledNumberType(1000),
TimePeriod: model.NewTimePeriodTypeWithRelativeEndTime(time.Minute * 2),
msg4 := &spineapi.Message{
RequestHeader: &model.HeaderType{
MsgCounter: util.Ptr(model.MsgCounterType(503)),
},
Cmd: model.CmdType{
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
{
LimitId: util.Ptr(model.LoadControlLimitIdType(0)),
IsLimitActive: util.Ptr(true),
Value: model.NewScaledNumberType(1000),
TimePeriod: model.NewTimePeriodTypeWithRelativeEndTime(time.Minute * 2),
},
},
},
},
DeviceRemote: s.remoteDevice,
EntityRemote: s.monitoredEntity,
}

s.sut.loadControlWriteCB(&msg3)
s.sut.loadControlWriteCB(msg4)
assert.True(s.T(), s.eventCalled)
s.eventCalled = false

msg4 := msg
msg4.RequestHeader.MsgCounter = util.Ptr(model.MsgCounterType(504))
msg4.Cmd = model.CmdType{
Filter: []model.FilterType{
{
CmdControl: &model.CmdControlType{
Partial: util.Ptr(model.ElementTagType{}),
},
},
msg5 := &spineapi.Message{
RequestHeader: &model.HeaderType{
MsgCounter: util.Ptr(model.MsgCounterType(504)),
},
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
Cmd: model.CmdType{
Filter: []model.FilterType{
{
LimitId: util.Ptr(model.LoadControlLimitIdType(0)),
IsLimitActive: util.Ptr(true),
Value: model.NewScaledNumberType(5000),
TimePeriod: model.NewTimePeriodTypeWithRelativeEndTime(time.Hour * 3),
CmdControl: &model.CmdControlType{
Partial: util.Ptr(model.ElementTagType{}),
},
},
},
},
LoadControlLimitListData: &model.LoadControlLimitListDataType{
LoadControlLimitData: []model.LoadControlLimitDataType{
{
LimitId: util.Ptr(model.LoadControlLimitIdType(0)),
IsLimitActive: util.Ptr(true),
Value: model.NewScaledNumberType(5000),
TimePeriod: model.NewTimePeriodTypeWithRelativeEndTime(time.Hour * 3),
},
},
}},
DeviceRemote: s.remoteDevice,
EntityRemote: s.monitoredEntity,
}

s.sut.loadControlWriteCB(&msg4)
s.sut.loadControlWriteCB(msg5)
assert.True(s.T(), s.eventCalled)
s.eventCalled = false
}

func (s *CsLPCSuite) Test_UpdateUseCaseAvailability() {
Expand Down

0 comments on commit 9166603

Please sign in to comment.