Commit cb230b69 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet Committed by Brian Tiger Chow

bugfix: service has a Start func

We were issuing handling goroutines in both NewService and Start
parent f9650a79
......@@ -11,7 +11,8 @@ import (
func NewServiceWrapper(ctx context.Context, r Receiver) Sender {
h := &handlerWrapper{r}
s := netservice.NewService(ctx, h)
s := netservice.NewService(h)
s.Start(ctx)
return &senderWrapper{s}
}
......
......@@ -37,16 +37,12 @@ type Service struct {
}
// NewService creates a service object with given type ID and Handler
func NewService(ctx context.Context, h Handler) *Service {
s := &Service{
func NewService(h Handler) *Service {
return &Service{
Handler: h,
Requests: RequestMap{},
Pipe: msg.NewPipe(10),
}
go s.handleIncomingMessages(ctx)
return s
}
// Start kicks off the Service goroutines.
......
......@@ -39,9 +39,13 @@ func newPeer(t *testing.T, id string) *peer.Peer {
func TestServiceHandler(t *testing.T) {
ctx := context.Background()
h := &ReverseHandler{}
s := NewService(ctx, h)
s := NewService(h)
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
if err := s.Start(ctx); err != nil {
t.Error(err)
}
d, err := wrapData([]byte("beep"), nil)
if err != nil {
t.Error(err)
......@@ -67,8 +71,17 @@ func TestServiceHandler(t *testing.T) {
func TestServiceRequest(t *testing.T) {
ctx := context.Background()
s1 := NewService(ctx, &ReverseHandler{})
s2 := NewService(ctx, &ReverseHandler{})
s1 := NewService(&ReverseHandler{})
s2 := NewService(&ReverseHandler{})
if err := s1.Start(ctx); err != nil {
t.Error(err)
}
if err := s2.Start(ctx); err != nil {
t.Error(err)
}
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
// patch services together
......@@ -98,10 +111,18 @@ func TestServiceRequest(t *testing.T) {
func TestServiceRequestTimeout(t *testing.T) {
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond)
s1 := NewService(ctx, &ReverseHandler{})
s2 := NewService(ctx, &ReverseHandler{})
s1 := NewService(&ReverseHandler{})
s2 := NewService(&ReverseHandler{})
peer1 := newPeer(t, "11140beec7b5ea3f0fdbc95d0dd47f3c5bc275aaaaaa")
if err := s1.Start(ctx); err != nil {
t.Error(err)
}
if err := s2.Start(ctx); err != nil {
t.Error(err)
}
// patch services together
go func() {
for {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment