Browse Source

NewXXXServer doesnt run Start or return error

pull/1780/head
Ethan Buchman 8 years ago
parent
commit
d07b2352ad
9 changed files with 35 additions and 25 deletions
  1. +4
    -0
      cmd/counter/main.go
  2. +4
    -0
      cmd/dummy/main.go
  3. +4
    -0
      example/block_aware/block_aware_app.go
  4. +3
    -0
      example/block_aware/block_aware_test.go
  5. +10
    -11
      example/dummy/dummy_test.go
  6. +4
    -4
      example/example_test.go
  7. +2
    -3
      server/grpc_server.go
  8. +2
    -2
      server/server.go
  9. +2
    -5
      server/socket_server.go

+ 4
- 0
cmd/counter/main.go View File

@ -27,6 +27,10 @@ func main() {
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {


+ 4
- 0
cmd/dummy/main.go View File

@ -36,6 +36,10 @@ func main() {
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {


+ 4
- 0
example/block_aware/block_aware_app.go View File

@ -25,6 +25,10 @@ func main() {
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {


+ 3
- 0
example/block_aware/block_aware_test.go View File

@ -20,6 +20,9 @@ func TestChainAware(t *testing.T) {
t.Fatal(err)
}
srv.SetLogger(log.TestingLogger().With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
t.Fatal(err.Error())
}
defer srv.Stop()
// Connect to the socket


+ 10
- 11
example/dummy/dummy_test.go View File

@ -214,22 +214,21 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client,
socket := cmn.Fmt("unix://%s.sock", name)
logger := log.TestingLogger()
server, err := server.NewSocketServer(socket, app)
if err != nil {
server := server.NewSocketServer(socket, app)
server.SetLogger(logger.With("module", "abci-server"))
if _, err := server.Start(); err != nil {
return nil, nil, err
}
server.SetLogger(logger.With("module", "abci-server"))
// Connect to the socket
client := abcicli.NewSocketClient(socket, false)
client.SetLogger(logger.With("module", "abci-client"))
if _, err := client.Start(); err != nil {
server.Stop()
return nil, nil, err
}
client.SetLogger(logger.With("module", "abci-client"))
client.Start()
return client, server, err
return client, server, nil
}
func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, cmn.Service, error) {
@ -238,19 +237,19 @@ func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, c
logger := log.TestingLogger()
gapp := types.NewGRPCApplication(app)
server, err := server.NewGRPCServer(socket, gapp)
if err != nil {
server := server.NewGRPCServer(socket, gapp)
server.SetLogger(logger.With("module", "abci-server"))
if _, err := server.Start(); err != nil {
return nil, nil, err
}
server.SetLogger(logger.With("module", "abci-server"))
client := abcicli.NewGRPCClient(socket, true)
client.SetLogger(logger.With("module", "abci-client"))
if _, err := client.Start(); err != nil {
server.Stop()
return nil, nil, err
}
client.SetLogger(logger.With("module", "abci-client"))
return client, server, err
return client, server, nil
}
func TestClientServer(t *testing.T) {


+ 4
- 4
example/example_test.go View File

@ -38,8 +38,8 @@ func testStream(t *testing.T, app types.Application) {
numDeliverTxs := 200000
// Start the listener
server, err := server.NewSocketServer("unix://test.sock", app)
if err != nil {
server := server.NewSocketServer("unix://test.sock", app)
if _, err := server.Start(); err != nil {
t.Fatalf("Error starting socket server: %v", err.Error())
}
server.SetLogger(log.TestingLogger().With("module", "abci-server"))
@ -112,8 +112,8 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
numDeliverTxs := 2000
// Start the listener
server, err := server.NewGRPCServer("unix://test.sock", app)
if err != nil {
server := server.NewGRPCServer("unix://test.sock", app)
if _, err := server.Start(); err != nil {
t.Fatalf("Error starting GRPC server: %v", err.Error())
}
server.SetLogger(log.TestingLogger().With("module", "abci-server"))


+ 2
- 3
server/grpc_server.go View File

@ -22,7 +22,7 @@ type GRPCServer struct {
}
// NewGRPCServer returns a new gRPC ABCI server
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (cmn.Service, error) {
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) cmn.Service {
parts := strings.SplitN(protoAddr, "://", 2)
proto, addr := parts[0], parts[1]
s := &GRPCServer{
@ -32,8 +32,7 @@ func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (cmn.Servi
app: app,
}
s.BaseService = *cmn.NewBaseService(nil, "ABCIServer", s)
_, err := s.Start() // Just start it
return s, err
return s
}
// OnStart starts the gRPC service


+ 2
- 2
server/server.go View File

@ -21,9 +21,9 @@ func NewServer(protoAddr, transport string, app types.Application) (cmn.Service,
var err error
switch transport {
case "socket":
s, err = NewSocketServer(protoAddr, app)
s = NewSocketServer(protoAddr, app)
case "grpc":
s, err = NewGRPCServer(protoAddr, types.NewGRPCApplication(app))
s = NewGRPCServer(protoAddr, types.NewGRPCApplication(app))
default:
err = fmt.Errorf("Unknown server type %s", transport)
}


+ 2
- 5
server/socket_server.go View File

@ -29,7 +29,7 @@ type SocketServer struct {
app types.Application
}
func NewSocketServer(protoAddr string, app types.Application) (cmn.Service, error) {
func NewSocketServer(protoAddr string, app types.Application) cmn.Service {
parts := strings.SplitN(protoAddr, "://", 2)
proto, addr := parts[0], parts[1]
s := &SocketServer{
@ -40,10 +40,7 @@ func NewSocketServer(protoAddr string, app types.Application) (cmn.Service, erro
conns: make(map[int]net.Conn),
}
s.BaseService = *cmn.NewBaseService(nil, "ABCIServer", s)
// FIXME we are loosing "Starting ABCIServer" message here
// add logger to params?
_, err := s.Start() // Just start it
return s, err
return s
}
func (s *SocketServer) OnStart() error {


Loading…
Cancel
Save