Skip to content

Commit

Permalink
RSDK-2672: tests using Incremental/Single encoder should use construc…
Browse files Browse the repository at this point in the history
…tor, not initialization (#2647)
  • Loading branch information
martha-johnston authored Jul 18, 2023
1 parent 8a65dfc commit 4dabc8b
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 78 deletions.
13 changes: 6 additions & 7 deletions components/encoder/incremental/incremental_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ type Encoder struct {
encBName string

logger golog.Logger
// TODO(RSDK-2672): This is exposed for tests and should be unexported with
// the constructor being used instead.
CancelCtx context.Context

cancelCtx context.Context
cancelFunc func()
activeBackgroundWorkers sync.WaitGroup
}
Expand Down Expand Up @@ -98,7 +97,7 @@ func NewIncrementalEncoder(
e := &Encoder{
Named: conf.ResourceName().AsNamed(),
logger: logger,
CancelCtx: cancelCtx,
cancelCtx: cancelCtx,
cancelFunc: cancelFunc,
position: 0,
positionType: encoder.PositionTypeTicks,
Expand Down Expand Up @@ -154,7 +153,7 @@ func (e *Encoder) Reconfigure(
}
utils.UncheckedError(e.Close(ctx))
cancelCtx, cancelFunc := context.WithCancel(context.Background())
e.CancelCtx = cancelCtx
e.cancelCtx = cancelCtx
e.cancelFunc = cancelFunc

e.mu.Lock()
Expand Down Expand Up @@ -239,15 +238,15 @@ func (e *Encoder) Start(ctx context.Context) {
// statement guarantees that we'll return if we're supposed to, regardless of whether
// there's data in the other channels.
select {
case <-e.CancelCtx.Done():
case <-e.cancelCtx.Done():
return
default:
}

var tick board.Tick

select {
case <-e.CancelCtx.Done():
case <-e.cancelCtx.Done():
return
case tick = <-chanA:
aLevel = 0
Expand Down
13 changes: 6 additions & 7 deletions components/encoder/single/single_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ type Encoder struct {

positionType encoder.PositionType
logger golog.Logger
// TODO(RSDK-2672): This is exposed for tests and should be unexported with
// the constructor being used instead.
CancelCtx context.Context

cancelCtx context.Context
cancelFunc func()
activeBackgroundWorkers sync.WaitGroup
}
Expand Down Expand Up @@ -119,7 +118,7 @@ func NewSingleEncoder(
e := &Encoder{
Named: conf.ResourceName().AsNamed(),
logger: logger,
CancelCtx: cancelCtx,
cancelCtx: cancelCtx,
cancelFunc: cancelFunc,
position: 0,
positionType: encoder.PositionTypeTicks,
Expand Down Expand Up @@ -164,7 +163,7 @@ func (e *Encoder) Reconfigure(
}
utils.UncheckedError(e.Close(ctx))
cancelCtx, cancelFunc := context.WithCancel(context.Background())
e.CancelCtx = cancelCtx
e.cancelCtx = cancelCtx
e.cancelFunc = cancelFunc

e.mu.Lock()
Expand All @@ -189,13 +188,13 @@ func (e *Encoder) Start(ctx context.Context) {
defer e.I.RemoveCallback(encoderChannel)
for {
select {
case <-e.CancelCtx.Done():
case <-e.cancelCtx.Done():
return
default:
}

select {
case <-e.CancelCtx.Done():
case <-e.cancelCtx.Done():
return
case <-encoderChannel:
}
Expand Down
Loading

0 comments on commit 4dabc8b

Please sign in to comment.