File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ func NewManager(cfg *Config) *Manager {
3636}
3737
3838// Run runs the reservation manager.
39- func (m * Manager ) Run (ctx context.Context , height int32 ) error {
39+ func (m * Manager ) Run (ctx context.Context , height int32 ,
40+ initChan chan struct {}) error {
41+
4042 log .Debugf ("Starting reservation manager" )
4143
4244 runCtx , cancel := context .WithCancel (ctx )
@@ -58,6 +60,8 @@ func (m *Manager) Run(ctx context.Context, height int32) error {
5860
5961 ntfnChan := m .cfg .NotificationManager .SubscribeReservations (runCtx )
6062
63+ close (initChan )
64+
6165 for {
6266 select {
6367 case height := <- newBlockChan :
Original file line number Diff line number Diff line change @@ -25,12 +25,16 @@ func TestManager(t *testing.T) {
2525
2626 testContext := newManagerTestContext (t )
2727
28+ initChan := make (chan struct {})
2829 // Start the manager.
2930 go func () {
30- err := testContext .manager .Run (ctxb , testContext .mockLnd .Height )
31+ err := testContext .manager .Run (ctxb , testContext .mockLnd .Height , initChan )
3132 require .NoError (t , err )
3233 }()
3334
35+ // We'll now wait for the manager to be initialized.
36+ <- initChan
37+
3438 // Create a new reservation.
3539 reservationFSM , err := testContext .manager .newReservation (
3640 ctxb , uint32 (testContext .mockLnd .Height ),
Original file line number Diff line number Diff line change @@ -648,6 +648,7 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
648648 // Start the reservation manager.
649649 if d .reservationManager != nil {
650650 d .wg .Add (1 )
651+ initChan := make (chan struct {})
651652 go func () {
652653 defer d .wg .Done ()
653654
@@ -663,12 +664,24 @@ func (d *Daemon) initialize(withMacaroonService bool) error {
663664 defer log .Info ("Reservation manager stopped" )
664665
665666 err = d .reservationManager .Run (
666- d .mainCtx , int32 (getInfo .BlockHeight ),
667+ d .mainCtx , int32 (getInfo .BlockHeight ), initChan ,
667668 )
668669 if err != nil && ! errors .Is (err , context .Canceled ) {
669670 d .internalErrChan <- err
670671 }
671672 }()
673+
674+ // Wait for the reservation server to be ready before starting the
675+ // grpc server.
676+ timeOutCtx , cancel := context .WithTimeout (d .mainCtx , 10 * time .Second )
677+ select {
678+ case <- timeOutCtx .Done ():
679+ cancel ()
680+ return fmt .Errorf ("reservation server not ready: %v" ,
681+ timeOutCtx .Err ())
682+ case <- initChan :
683+ cancel ()
684+ }
672685 }
673686
674687 // Start the instant out manager.
You can’t perform that action at this time.
0 commit comments