Skip to content

Commit

Permalink
fix: fix hang in test worker
Browse files Browse the repository at this point in the history
  • Loading branch information
laouji committed Dec 20, 2024
1 parent 1930e92 commit 18f9f1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ func (s *Server) Start() error {
}()

select {
case <-ctx.Done():
return errors.New("unexpected context cancel before server ready")
case <-service.Ready(ctx):
case err := <-s.errorChan:
cancel()
Expand Down
7 changes: 7 additions & 0 deletions pkg/testserver/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewWorker(configuration Configuration, logger Logger) *Worker {
return &Worker{
configuration: configuration,
logger: logger,
errorChan: make(chan error, 1),
}
}

Expand All @@ -45,7 +46,13 @@ func (w *Worker) Start(args []string) error {
ctx = service.ContextWithLifecycle(ctx)
ctx, cancel := context.WithCancel(ctx)

go func() {
w.errorChan <- rootCmd.ExecuteContext(ctx)
}()

select {
case <-ctx.Done():
return errors.New("unexpected context cancel before worker ready")
case <-service.Ready(ctx):
case err := <-w.errorChan:
cancel()
Expand Down

0 comments on commit 18f9f1c

Please sign in to comment.