Skip to content

Commit

Permalink
fix: wait for pulsar proper startup (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum authored Apr 11, 2023
1 parent e7afeb1 commit 154ff20
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 1 addition & 6 deletions testhelper/docker/resource/pulsar.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"runtime"
"strings"

"github.com/ory/dockertest/v3"
"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource/pulsar"
Expand Down Expand Up @@ -52,17 +51,13 @@ func SetupPulsar(pool *dockertest.Pool, d cleaner, opts ...pulsar.Opt) (*PulsarR

if err := pool.Retry(func() (err error) {
var w bytes.Buffer
code, err := pulsarContainer.Exec([]string{"bin/pulsar-admin", "brokers", "healthcheck"}, dockertest.ExecOptions{StdOut: &w, StdErr: &w})
code, err := pulsarContainer.Exec([]string{"sh", "-c", "curl -I http://localhost:8080/admin/v2/namespaces/public/default | grep '200' || exit 1"}, dockertest.ExecOptions{StdOut: &w, StdErr: &w})
if err != nil {
return err
}
if code != 0 {
return fmt.Errorf("pulsar healthcheck failed")
}
out := strings.ReplaceAll(w.String(), "\n", "")
if !strings.Contains(out, "ok") {
return fmt.Errorf("pulsar healthcheck failed")
}
return nil
}); err != nil {
return nil, err
Expand Down
21 changes: 21 additions & 0 deletions testhelper/docker/resource/pulsar_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package resource_test

import (
"net/http"
"testing"

"github.com/ory/dockertest/v3"
"github.com/rudderlabs/rudder-go-kit/httputil"
"github.com/rudderlabs/rudder-go-kit/testhelper/docker/resource"
"github.com/stretchr/testify/require"
)

func TestPulsar(t *testing.T) {
pool, err := dockertest.NewPool("")
require.NoError(t, err)
pulsarContainer, err := resource.SetupPulsar(pool, t)
require.NoError(t, err)
res, err := http.Head(pulsarContainer.AdminURL + "/admin/v2/namespaces/public/default")
defer func() { httputil.CloseResponse(res) }()
require.NoError(t, err)
}

0 comments on commit 154ff20

Please sign in to comment.