Skip to content

Commit

Permalink
Agent tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscatolini committed Apr 16, 2018
1 parent 87b8467 commit 29547a2
Show file tree
Hide file tree
Showing 3 changed files with 726 additions and 63 deletions.
51 changes: 26 additions & 25 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package agent

import (
"encoding/json"
"errors"
"fmt"
"net"
"reflect"
Expand Down Expand Up @@ -234,30 +235,6 @@ func (a *Agent) SetStatus(state int32) {
atomic.StoreInt32(&a.state, state)
}

func hbdEncode(heartbeatTimeout time.Duration, packetEncoder codec.PacketEncoder) {
hData := map[string]interface{}{
"code": 200,
"sys": map[string]interface{}{
"heartbeat": heartbeatTimeout.Seconds(),
"dict": message.GetDictionary(),
},
}
data, err := json.Marshal(hData)
if err != nil {
panic(err)
}

hrd, err = packetEncoder.Encode(packet.Handshake, data)
if err != nil {
panic(err)
}

hbd, err = packetEncoder.Encode(packet.Heartbeat, nil)
if err != nil {
panic(err)
}
}

// Handle handles the messages from and to a client
func (a *Agent) Handle() {
defer func() {
Expand Down Expand Up @@ -377,7 +354,7 @@ func (a *Agent) write() {

// SendRequest sends a request to a server
func (a *Agent) SendRequest(serverID, route string, v interface{}) (*protos.Response, error) {
return nil, fmt.Errorf("not implemented")
return nil, errors.New("not implemented")
}

// AnswerWithError answers with an error
Expand All @@ -392,3 +369,27 @@ func (a *Agent) AnswerWithError(mid uint, err error) {
log.Error("error answering the player with an error: ", e.Error())
}
}

func hbdEncode(heartbeatTimeout time.Duration, packetEncoder codec.PacketEncoder) {
hData := map[string]interface{}{
"code": 200,
"sys": map[string]interface{}{
"heartbeat": heartbeatTimeout.Seconds(),
"dict": message.GetDictionary(),
},
}
data, err := json.Marshal(hData)
if err != nil {
panic(err)
}

hrd, err = packetEncoder.Encode(packet.Handshake, data)
if err != nil {
panic(err)
}

hbd, err = packetEncoder.Encode(packet.Heartbeat, nil)
if err != nil {
panic(err)
}
}
Loading

0 comments on commit 29547a2

Please sign in to comment.