Skip to content

Commit

Permalink
Fix issues 89 and 87 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
halturin authored Jan 4, 2022
1 parent 7307b1d commit 9017f69
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gen/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ func (gs *Server) ProcessLoop(ps ProcessState, started chan<- bool) string {
case direct := <-channels.Direct:
gsp.waitCallbackOrDeferr(direct)
continue
case gsp.waitReply = <-gsp.callbackWaitReply:
continue
}

lib.Log("[%s] GEN_SERVER %s got message from %s", gsp.NodeName(), gsp.Self(), fromPid)
Expand Down
5 changes: 4 additions & 1 deletion node/epmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ func (e *epmd) Init(ctx context.Context, name string, port uint16, opts Options)
// trying to start embedded EPMD before we go further
Server(ctx, e.Port)
}
dialer := net.Dialer{
KeepAlive: 15 * time.Second,
}
dsn := net.JoinHostPort("", strconv.Itoa(int(e.Port)))
conn, err := net.Dial("tcp", dsn)
conn, err := dialer.Dial("tcp", dsn)
if err != nil {
ready <- err
return
Expand Down
76 changes: 76 additions & 0 deletions tests/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,82 @@ func (gs *messageOrderGS) HandleDirect(process *gen.ServerProcess, message inter
return nil, fmt.Errorf("incorrect direct call")
}

type GSCallPanic struct {
gen.Server
}

func (gs *GSCallPanic) Init(process *gen.ServerProcess, args ...etf.Term) error {
return nil
}

func (gs *GSCallPanic) HandleCall(process *gen.ServerProcess, from gen.ServerFrom, message etf.Term) (etf.Term, gen.ServerStatus) {
m := message.(string)
if m == "panic" {
panic("test")
}

return "ok", gen.ServerStatusOK
}

func (gs *GSCallPanic) HandleDirect(process *gen.ServerProcess, message interface{}) (interface{}, error) {

pids, ok := message.([]etf.Pid)
if !ok {
return nil, fmt.Errorf("not a pid")
}
if _, err := process.CallWithTimeout(pids[0], "panic", 1); err == nil {
return nil, fmt.Errorf("must be error here")
}

v, err := process.Call(pids[1], "test")
if err != nil {
return nil, err
}
if v.(string) != "ok" {
return nil, fmt.Errorf("wrong result %#v", v)
}

return nil, nil
}

func TestServerCallServerWithPanic(t *testing.T) {
fmt.Printf("\n=== Test Server. Making a Call to Server with panic (issue 86) \n")
fmt.Printf("Starting node: nodeGSCallWithPanic1@localhost: ")
node1, err1 := ergo.StartNode("nodeGSCallWithPanic1@localhost", "cookies", node.Options{})
if err1 != nil {
t.Fatal("can't start node", err1)
} else {
fmt.Println("OK")
}
fmt.Printf("Starting node: nodeGSCallWithPanic2@localhost: ")
node2, err2 := ergo.StartNode("nodeGSCallWithPanic2@localhost", "cookies", node.Options{})
if err2 != nil {
t.Fatal("can't start node", err2)
} else {
fmt.Println("OK")
}

p1n1, err := node1.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
if err != nil {
t.Fatal(err)
}
p1n2, err := node2.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
if err != nil {
t.Fatal(err)
}
p2n2, err := node2.Spawn("", gen.ProcessOptions{}, &GSCallPanic{})
if err != nil {
t.Fatal(err)
}

pids := []etf.Pid{p1n2.Self(), p2n2.Self()}

if _, err := p1n1.Direct(pids); err != nil {
t.Fatal(err)
}
fmt.Println("OK")
}

func TestServerMessageOrder(t *testing.T) {
fmt.Printf("\n=== Test Server message order\n")
fmt.Printf("Starting node: nodeGS1MessageOrder@localhost: ")
Expand Down

0 comments on commit 9017f69

Please sign in to comment.