Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshsharma14317 committed Dec 7, 2023
1 parent b57dc14 commit e2eaf4a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/org/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestOrganizationWorkflow(t *testing.T) {

group.Go(func() error { return srv.ServeGRPC(cctx) })
group.Go(func() error { return srv.ServeHTTP(cctx) })
err = mock.CheckServerStatus(srv)
err = mock.CheckServerStatus()
require.NoError(t, err)

var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestServiceWorkflow(t *testing.T) {

group.Go(func() error { return srv.ServeGRPC(cctx) })
group.Go(func() error { return srv.ServeHTTP(cctx) })
err = mock.CheckServerStatus(srv)
err = mock.CheckServerStatus()
require.NoError(t, err)

var buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestUserWorkflow(t *testing.T) {

group.Go(func() error { return srv.ServeGRPC(cctx) })
group.Go(func() error { return srv.ServeHTTP(cctx) })
err = mock.CheckServerStatus(srv)
err = mock.CheckServerStatus()
require.NoError(t, err)

var buf bytes.Buffer
Expand Down
28 changes: 14 additions & 14 deletions cli/pkg/mock/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,21 @@ func (m *mockGithub) InstallationToken(ctx context.Context, installationID int64
return "", nil
}

func CheckServerStatus(srv *server.Server) error {
func CheckServerStatus() error {
client := &http.Client{}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()
resultChan := make(chan error, 1)

go func() {
resp, err := http.Get("http://localhost:8080/v1/ping")
defer resp.Body.Close()
resultChan <- err
}()

select {
case err := <-resultChan:
return err
case <-ctx.Done():
return fmt.Errorf("server is not responding within the timeout period")
for {
select {
case <-ctx.Done():
return fmt.Errorf("server took too long to start")
default:
resp, err := client.Get("http://localhost:8080/v1/ping")
if err == nil {
resp.Body.Close()
return nil
}
time.Sleep(100 * time.Millisecond) // Wait and retry
}
}
}

0 comments on commit e2eaf4a

Please sign in to comment.