Skip to content

Commit 7fca08f

Browse files
Olle Sandbergodsod
authored andcommitted
canrunner: Set cyclic transmission on RunMessageTransmitter init
Check before starting the transmit loop if cyclic transmission has already been requested and enable it if so.
1 parent 644519b commit 7fca08f

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

pkg/canrunner/run.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ func RunMessageTransmitter(
152152
cyclicTransmissionTicker.Stop()
153153
cyclicTransmissionTicker = nil
154154
}
155+
setCyclicTransmission := func() {
156+
l.Lock()
157+
isCyclicTransmissionEnabled := m.IsCyclicTransmissionEnabled()
158+
l.Unlock()
159+
if isCyclicTransmissionEnabled {
160+
enableCyclicTransmission()
161+
} else {
162+
disableCyclicTransmission()
163+
}
164+
}
155165
transmit := func() error {
156166
l.Lock()
157167
hook := m.BeforeTransmitHook()
@@ -173,20 +183,14 @@ func RunMessageTransmitter(
173183
}
174184
ctxDone := ctx.Done()
175185
transmitEventChan := m.TransmitEventChan()
186+
setCyclicTransmission()
176187
wakeUpChan := m.WakeUpChan()
177188
for {
178189
select {
179190
case <-ctxDone:
180191
return nil
181192
case <-wakeUpChan:
182-
l.Lock()
183-
isCyclicTransmissionEnabled := m.IsCyclicTransmissionEnabled()
184-
l.Unlock()
185-
if isCyclicTransmissionEnabled {
186-
enableCyclicTransmission()
187-
} else {
188-
disableCyclicTransmission()
189-
}
193+
setCyclicTransmission()
190194
case <-transmitEventChan:
191195
if err := transmit(); err != nil {
192196
return err

pkg/canrunner/run_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ func TestRunMessageTransmitter_TransmitEventMessage(t *testing.T) {
9191
g.Go(func() error {
9292
return canrunner.RunMessageTransmitter(ctx, tx, node, msg, clock)
9393
})
94+
// then message should be queried for if it has cyclic transmission enabled
95+
node.EXPECT().Lock()
96+
msg.EXPECT().IsCyclicTransmissionEnabled()
97+
node.EXPECT().Unlock()
9498
// then the node should be locked
9599
node.EXPECT().Lock()
96100
// and the time should be queried

0 commit comments

Comments
 (0)