diff --git a/internal/agent/agent.go b/internal/agent/agent.go index eb7eaac..3e410a8 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -81,7 +81,11 @@ func New(config Config) (*Agent, error) { return nil, err } } - go a.serve() + go func() { + if err := a.serve(); err != nil { + logger.Fatal("agent failed", zap.Error(err)) + } + }() return a, nil } @@ -113,7 +117,7 @@ func (a *Agent) setupLog() error { if _, err := reader.Read(b); err != nil { return false } - return bytes.Compare(b, []byte{byte(log.RaftRPC)}) == 0 + return bytes.Equal(b, []byte{byte(log.RaftRPC)}) }) logConfig := log.Config{} logConfig.Raft.StreamLayer = log.NewStreamLayer( diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 728daaf..5aee631 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -12,6 +12,7 @@ import ( "github.com/travisjeffery/go-dynaport" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/status" api "github.com/garrettladley/dclog/api/v1" "github.com/garrettladley/dclog/internal/agent" @@ -123,8 +124,8 @@ func TestAgent(t *testing.T) { ) require.Nil(t, consumeResponse) require.Error(t, err) - got := grpc.Code(err) - want := grpc.Code(api.ErrOffsetOutOfRange{}.GRPCStatus().Err()) + got := status.Code(err) + want := status.Code(api.ErrOffsetOutOfRange{}.GRPCStatus().Err()) require.Equal(t, got, want) } @@ -133,7 +134,7 @@ func client(t *testing.T, agent *agent.Agent, tlsConfig *tls.Config) api.LogClie opts := []grpc.DialOption{grpc.WithTransportCredentials(tlsCreds)} rpcAddr, err := agent.Config.RPCAddr() require.NoError(t, err) - conn, err := grpc.Dial(rpcAddr, opts...) + conn, err := grpc.NewClient(rpcAddr, opts...) require.NoError(t, err) client := api.NewLogClient(conn) return client diff --git a/internal/log/segment.go b/internal/log/segment.go index 97000a5..3eef46d 100644 --- a/internal/log/segment.go +++ b/internal/log/segment.go @@ -115,10 +115,3 @@ func (s *segment) Remove() error { } return nil } - -func nearestMultiple(j, k uint64) uint64 { - if j >= 0 { - return (j / k) * k - } - return ((j - k + 1) / k) * k -} diff --git a/internal/log/store_test.go b/internal/log/store_test.go index ee41262..8f224d2 100644 --- a/internal/log/store_test.go +++ b/internal/log/store_test.go @@ -77,13 +77,15 @@ func TestStoreClose(t *testing.T) { _, _, err = s.Append(write) require.NoError(t, err) - f, beforeSize, err := openFile(f.Name()) + var beforeSize int64 + f, beforeSize, err = openFile(f.Name()) require.NoError(t, err) err = s.Close() require.NoError(t, err) - f, afterSize, err := openFile(f.Name()) + var afterSize int64 + f, afterSize, err = openFile(f.Name()) require.True(t, afterSize > beforeSize) } diff --git a/internal/server/server_test.go b/internal/server/server_test.go index bc9a338..9d16a08 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -1,9 +1,9 @@ package server import ( - // ... "context" "flag" + "fmt" "net" "os" "testing" @@ -24,8 +24,6 @@ import ( "github.com/garrettladley/dclog/internal/log" ) -// imports... - var debug = flag.Bool("debug", false, "Enable observability for debugging.") func TestMain(m *testing.M) { @@ -89,7 +87,7 @@ func setupTest(t *testing.T, fn func(*Config)) ( require.NoError(t, err) tlsCreds := credentials.NewTLS(tlsConfig) opts := []grpc.DialOption{grpc.WithTransportCredentials(tlsCreds)} - conn, err := grpc.Dial(l.Addr().String(), opts...) + conn, err := grpc.NewClient(l.Addr().String(), opts...) require.NoError(t, err) client := api.NewLogClient(conn) return conn, client, opts @@ -157,7 +155,9 @@ func setupTest(t *testing.T, fn func(*Config)) ( require.NoError(t, err) go func() { - server.Serve(l) + if err := server.Serve(l); err != nil { + panic(fmt.Errorf("server serve: %w", err)) + } }() return rootClient, nobodyClient, cfg, func() {