reservation: add initchan

This fixes a flake in the unit tests
This commit is contained in:
sputn1ck 2024-10-21 21:46:38 +02:00
parent 246becb10a
commit f2fb722901
No known key found for this signature in database
GPG key ID: 671103D881A5F0E4
3 changed files with 28 additions and 4 deletions

View file

@ -34,7 +34,9 @@ func NewManager(cfg *Config) *Manager {
}
// Run runs the reservation manager.
func (m *Manager) Run(ctx context.Context, height int32) error {
func (m *Manager) Run(ctx context.Context, height int32,
initChan chan struct{}) error {
log.Debugf("Starting reservation manager")
runCtx, cancel := context.WithCancel(ctx)
@ -55,6 +57,9 @@ func (m *Manager) Run(ctx context.Context, height int32) error {
ntfnChan := m.cfg.NotificationManager.SubscribeReservations(runCtx)
// Signal that the manager has been initialized.
close(initChan)
for {
select {
case height := <-newBlockChan:

View file

@ -25,12 +25,16 @@ func TestManager(t *testing.T) {
testContext := newManagerTestContext(t)
initChan := make(chan struct{})
// Start the manager.
go func() {
err := testContext.manager.Run(ctxb, testContext.mockLnd.Height)
err := testContext.manager.Run(ctxb, testContext.mockLnd.Height, initChan)
require.NoError(t, err)
}()
// We'll now wait for the manager to be initialized.
<-initChan
// Create a new reservation.
reservationFSM, err := testContext.manager.newReservation(
ctxb, uint32(testContext.mockLnd.Height),