Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
erikstmartin committed Nov 29, 2012
2 parents 9bba884 + 1837d78 commit 69ce49a
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ examples/.vagrant
examples/testing/fibonacci/fibservice/fibservice
examples/testing/fibonacci/fibclient/fibclient
examples/testing/vagranttests/vagranttests
examples/testing/sleeper/sleepclient/sleepclient
examples/testing/sleeper/sleepservice/sleepservice
*~
*.swp
53 changes: 51 additions & 2 deletions all.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
# Build / Test skylib
go build && go test

# Build Client
cd client && go build && go test
cd ..

# Build Service
cd service && go build && go test
cd ..

# Build Daemon
cd daemon && go build && go test
cd ..

# Build Pools
cd pools && go build && go test
cd ..

# Build RPC
cd rpc/bsonrpc && go build && go test
cd ../../

# Build / Test sky
cd sky && go build && go test
cd cmd/sky && go build && go test
cd ..

# Build / Test dashboard
cd dashboard && go build && go test
cd ..

# Build / Test skydaemon
cd skydaemon && go build && go test
cd ../../

# Build / Test examples
cd examples/client && go build && go test
cd ../

cd service && go build && go test
cd ../

cd tutorial/client && go build && go test
cd ../

cd service && go build && go test
cd ../../

cd examples/service && go build && go test
cd testing/fibonacci/fibclient && go build && go test
cd ../

cd fibservice && go build && go test
cd ../../

cd sleeper/sleepclient && go build && go test
cd ../

cd sleepservice && go build && go test
cd ../../

cd vagranttests && go build && go test
cd ../../../
7 changes: 7 additions & 0 deletions client/serviceclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func (se serviceError) Error() string {
return se.msg
}

type ServiceClientInterface interface {
SetTimeout(retry, giveup time.Duration)
GetTimeout() (retry, giveup time.Duration)
Send(ri *skynet.RequestInfo, fn string, in interface{}, out interface{}) (err error)
SendOnce(ri *skynet.RequestInfo, fn string, in interface{}, out interface{}) (err error)
}

type ServiceClient struct {
client *Client
Log skynet.SemanticLogger `json:"-"`
Expand Down
19 changes: 19 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package skynet

import (
"fmt"
"os"
"testing"
)

func clearEnv() {
os.Setenv("SKYNET_BIND_IP", "")
os.Setenv("SKYNET_MIN_PORT", "")
os.Setenv("SKYNET_MAX_PORT", "")
os.Setenv("SKYNET_DZHOST", "")
os.Setenv("SKYNET_DZNSHOST", "")
os.Setenv("SKYNET_DZDISCOVER", "")
os.Setenv("SKYNET_MGOSERVER", "")
os.Setenv("SKYNET_MGODB", "")
os.Setenv("SKYNET_REGION", "")
os.Setenv("SKYNET_VERSION", "")
}

func TestGetServiceConfigFromFlags(t *testing.T) {
clearEnv()

os.Args = []string{"test", "--l=localhost:1234", "--region=TestRegion",
"--doozer=localhost:8046", "--doozerboot=localhost:1232",
"--autodiscover=true",
Expand Down Expand Up @@ -39,6 +55,8 @@ func TestGetServiceConfigFromFlags(t *testing.T) {
}

func TestGetServiceConfigFromFlagsDefaults(t *testing.T) {
clearEnv()

os.Args = []string{"test"}

config, _ := GetServiceConfigFromFlags(os.Args[1:])
Expand All @@ -56,6 +74,7 @@ func TestGetServiceConfigFromFlagsDefaults(t *testing.T) {
}

if config.DoozerConfig.Uri != "127.0.0.1:8046" {
fmt.Println(config.DoozerConfig.Uri)
t.Error("DoozerUri not set to default value")
}

Expand Down
46 changes: 37 additions & 9 deletions service/servicerpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package service

import (
"fmt"
"github.com/bketelsen/skynet"
"labix.org/v2/mgo/bson"
"net"
"testing"
)

Expand All @@ -15,31 +18,56 @@ func (e EchoRPC) Stopped(s *Service) {}
func (e EchoRPC) Registered(s *Service) {}
func (e EchoRPC) Unregistered(s *Service) {}

func (e EchoRPC) Foo(rinfo RequestInfo, in M, out *M) (err error) {
func (e EchoRPC) Foo(rinfo *skynet.RequestInfo, in M, out *M) (err error) {
*out = M{
"Hi": in["Hi"],
}

return
}

func TestServiceRPCBasic(t *testing.T) {
srpc := NewServiceRPC(EchoRPC{})
var addr net.Addr

config := &skynet.ServiceConfig{}
service := CreateService(EchoRPC{}, config)
service.clientInfo = make(map[string]ClientInfo, 1)

addr = &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 123,
}

service.clientInfo["123"] = ClientInfo{
Address: addr,
}

srpc := NewServiceRPC(service)

in := M{"Hi": "there"}
out := &M{}

sin := ServiceRPCIn{
RequestInfo: RequestInfo{RequestID: "id"},
Method: "Foo",
In: in,
}
sout := ServiceRPCOut{
Out: out,
sin := skynet.ServiceRPCIn{
RequestInfo: &skynet.RequestInfo{
RequestID: "id",
OriginAddress: addr.String(),
ConnectionAddress: addr.String(),
},
Method: "Foo",
ClientID: "123",
}

sin.In, _ = bson.Marshal(in)

sout := skynet.ServiceRPCOut{}

err := srpc.Forward(sin, &sout)
if err != nil {
t.Error(err)
}

bson.Unmarshal(sout.Out, out)

if v, ok := (*out)["Hi"].(string); !ok || v != "there" {
t.Error(fmt.Sprintf("Expected %v, got %v", in, *out))
}
Expand Down

0 comments on commit 69ce49a

Please sign in to comment.