Skip to content

Commit

Permalink
Merge d8882d0 into 80f1200
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmgleite committed Jun 25, 2018
2 parents 80f1200 + d8882d0 commit f1f5401
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
11 changes: 6 additions & 5 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ func (c *Client) ConnectTo(addr string) error {
}

// SendRequest sends a request to the server
func (c *Client) SendRequest(route string, data []byte) error {
func (c *Client) SendRequest(route string, data []byte) (uint, error) {
return c.sendMsg(message.Request, route, data)
}

// SendNotify sends a notify to the server
func (c *Client) SendNotify(route string, data []byte) error {
return c.sendMsg(message.Notify, route, data)
_, err := c.sendMsg(message.Notify, route, data)
return err
}

func (c *Client) buildPacket(msg message.Message) ([]byte, error) {
Expand All @@ -351,7 +352,7 @@ func (c *Client) buildPacket(msg message.Message) ([]byte, error) {
}

// sendMsg sends the request to the server
func (c *Client) sendMsg(msgType message.Type, route string, data []byte) error {
func (c *Client) sendMsg(msgType message.Type, route string, data []byte) (uint, error) {
// TODO mount msg and encode
m := message.Message{
Type: msgType,
Expand All @@ -374,8 +375,8 @@ func (c *Client) sendMsg(msgType message.Type, route string, data []byte) error
}

if err != nil {
return err
return 0, err
}
_, err = c.conn.Write(p)
return err
return m.ID, err
}
38 changes: 19 additions & 19 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestHandlerCallToFront(t *testing.T) {

for _, table := range tables {
t.Run(table.req, func(t *testing.T) {
err = c.SendRequest(table.req, table.data)
_, err = c.SendRequest(table.req, table.data)
assert.NoError(t, err)

msg := helpers.ShouldEventuallyReceive(t, c.IncomingMsgChan).(*message.Message)
Expand All @@ -104,9 +104,9 @@ func TestGroupFront(t *testing.T) {
assert.NoError(t, err)
defer c2.Disconnect()

err = c1.SendRequest("connector.testsvc.testbind", []byte{})
_, err = c1.SendRequest("connector.testsvc.testbind", []byte{})
assert.NoError(t, err)
err = c2.SendRequest("connector.testsvc.testbind", []byte{})
_, err = c2.SendRequest("connector.testsvc.testbind", []byte{})
assert.NoError(t, err)

msg1 := helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan).(*message.Message)
Expand Down Expand Up @@ -153,12 +153,12 @@ func TestKick(t *testing.T) {
defer c2.Disconnect()

uid1 := uuid.New().String()
err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)

helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan)

err = c2.SendRequest("connector.testsvc.testrequestkickuser", []byte(uid1))
_, err = c2.SendRequest("connector.testsvc.testrequestkickuser", []byte(uid1))
assert.NoError(t, err)

helpers.ShouldEventuallyReceive(t, c2.IncomingMsgChan)
Expand All @@ -185,11 +185,11 @@ func TestSameUIDUserShouldBeKicked(t *testing.T) {
defer c2.Disconnect()

uid1 := uuid.New().String()
err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)
helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan)

err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)

helpers.ShouldEventuallyReceive(t, c2.IncomingMsgChan)
Expand Down Expand Up @@ -218,11 +218,11 @@ func TestSameUIDUserShouldBeKickedInDifferentServersFromSameType(t *testing.T) {
defer c2.Disconnect()

uid1 := uuid.New().String()
err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)
helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan, 1*time.Second)

err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)

helpers.ShouldEventuallyReceive(t, c2.IncomingMsgChan, 2*time.Second)
Expand Down Expand Up @@ -251,11 +251,11 @@ func TestSameUIDUserShouldNotBeKickedInDifferentServersFromDiffType(t *testing.T
defer c2.Disconnect()

uid1 := uuid.New().String()
err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)
helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan)

err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)

helpers.ShouldEventuallyReceive(t, c2.IncomingMsgChan)
Expand All @@ -277,11 +277,11 @@ func TestKickOnBack(t *testing.T) {
assert.NoError(t, err)
defer c1.Disconnect()

err = c1.SendRequest("game.testsvc.testbind", nil)
_, err = c1.SendRequest("game.testsvc.testbind", nil)
assert.NoError(t, err)
msg1 := helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan).(*message.Message)
assert.Equal(t, []byte("ack"), msg1.Data)
err = c1.SendRequest("game.testsvc.testrequestkickme", nil)
_, err = c1.SendRequest("game.testsvc.testrequestkickme", nil)
assert.NoError(t, err)

helpers.ShouldEventuallyReturn(t, func() bool {
Expand Down Expand Up @@ -309,10 +309,10 @@ func TestPushToUsers(t *testing.T) {
defer c2.Disconnect()

uid1 := uuid.New().String()
err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
_, err = c1.SendRequest("connector.testsvc.testbindid", []byte(uid1))
assert.NoError(t, err)
uid2 := uuid.New().String()
err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid2))
_, err = c2.SendRequest("connector.testsvc.testbindid", []byte(uid2))
assert.NoError(t, err)

msg1 := helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan, 1*time.Second).(*message.Message)
Expand Down Expand Up @@ -373,7 +373,7 @@ func TestForwardToBackend(t *testing.T) {

for _, table := range tables {
t.Run(table.req, func(t *testing.T) {
err = c.SendRequest(table.req, table.data)
_, err = c.SendRequest(table.req, table.data)
assert.NoError(t, err)

msg := helpers.ShouldEventuallyReceive(t, c.IncomingMsgChan).(*message.Message)
Expand Down Expand Up @@ -402,9 +402,9 @@ func TestGroupBack(t *testing.T) {
assert.NoError(t, err)
defer c2.Disconnect()

err = c1.SendRequest("game.testsvc.testbind", []byte{})
_, err = c1.SendRequest("game.testsvc.testbind", []byte{})
assert.NoError(t, err)
err = c2.SendRequest("game.testsvc.testbind", []byte{})
_, err = c2.SendRequest("game.testsvc.testbind", []byte{})
assert.NoError(t, err)

msg1 := helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan).(*message.Message)
Expand Down Expand Up @@ -464,7 +464,7 @@ func TestUserRPC(t *testing.T) {

for _, table := range tables {
t.Run(table.name, func(t *testing.T) {
err := c1.SendRequest(table.route, table.data)
_, err := c1.SendRequest(table.route, table.data)
assert.NoError(t, err)
msg := helpers.ShouldEventuallyReceive(t, c1.IncomingMsgChan).(*message.Message)
assert.Equal(t, table.res, msg.Data)
Expand Down

0 comments on commit f1f5401

Please sign in to comment.