Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func StartWith(ctx context.Context, peers []peer.Info, opts groupcache.Options)

var parent transport.Transport
if opts.Transport == nil {
parent = transport.NewHttpTransport(transport.HttpTransportOptions{})
parent = transport.NewHttpTransport(transport.HttpTransportOptions{Logger: opts.Logger})
} else {
parent = opts.Transport
}
Expand Down
35 changes: 35 additions & 0 deletions cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ limitations under the License.
package cluster_test

import (
"bytes"
"context"
"log/slog"
"strings"
"sync"
"testing"
"time"

"github.com/groupcache/groupcache-go/v3"
"github.com/groupcache/groupcache-go/v3/cluster"
Expand Down Expand Up @@ -81,3 +86,33 @@ func TestStartWithInvalidPeer(t *testing.T) {
assert.Nil(t, cluster.ListDaemons())
require.NoError(t, cluster.Shutdown(context.Background()))
}

type syncBuffer struct {
mu sync.Mutex
buf bytes.Buffer
}

func (s *syncBuffer) Write(p []byte) (int, error) {
s.mu.Lock()
defer s.mu.Unlock()
return s.buf.Write(p)
}

func (s *syncBuffer) String() string {
s.mu.Lock()
defer s.mu.Unlock()
return s.buf.String()
}

func TestStartLogsEveryDaemonToLogger(t *testing.T) {
var out syncBuffer
logger := slog.New(slog.NewTextHandler(&out, nil))

require.NoError(t, cluster.Start(context.Background(), 3, groupcache.Options{Logger: logger}))
defer func() { require.NoError(t, cluster.Shutdown(context.Background())) }()

// The listening message is logged from a goroutine after the server starts.
require.Eventually(t, func() bool {
return strings.Count(out.String(), "Listening on") == 3
}, 5*time.Second, 10*time.Millisecond)
}
2 changes: 1 addition & 1 deletion instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func New(opts Options) *Instance {
}

if opts.Transport == nil {
opts.Transport = transport.NewHttpTransport(transport.HttpTransportOptions{})
opts.Transport = transport.NewHttpTransport(transport.HttpTransportOptions{Logger: opts.Logger})
}

i := &Instance{
Expand Down
Loading