[#1705] engine: Use condition var for evacuation unit tests

To know exactly when the evacuation was completed,
a conditional variable was added.

Closes #1705

Change-Id: I86f6d7d2ad2b9759905b6b5e9341008cb74f5dfd
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2025-04-10 16:04:04 +03:00
parent 64c1392513
commit e06ecacf57
Signed by: dstepanov-yadro
GPG key ID: 237AF1A763293BC0
3 changed files with 29 additions and 11 deletions

View file

@ -139,7 +139,8 @@ type evacuationLimiter struct {
eg *errgroup.Group
cancel context.CancelFunc
guard sync.RWMutex
guard *sync.RWMutex
statusCond *sync.Cond // used in unit tests
}
func (l *evacuationLimiter) TryStart(ctx context.Context, shardIDs []string, result *EvacuateShardRes) (*errgroup.Group, context.Context, error) {
@ -165,6 +166,7 @@ func (l *evacuationLimiter) TryStart(ctx context.Context, shardIDs []string, res
startedAt: time.Now().UTC(),
result: result,
}
l.statusCond.Broadcast()
return l.eg, egCtx, nil
}
@ -180,6 +182,7 @@ func (l *evacuationLimiter) Complete(err error) {
l.state.processState = EvacuateProcessStateCompleted
l.state.errMessage = errMsq
l.state.finishedAt = time.Now().UTC()
l.statusCond.Broadcast()
l.eg = nil
}
@ -214,6 +217,7 @@ func (l *evacuationLimiter) ResetEvacuationStatus() error {
l.state = EvacuationState{}
l.eg = nil
l.cancel = nil
l.statusCond.Broadcast()
return nil
}