Skip to content

Commit

Permalink
Develop (#239)
Browse files Browse the repository at this point in the history
* resolve test cases

Co-authored-by: fuzengyao <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: denghuaguang <[email protected]>
Co-authored-by: myxy99 <[email protected]>
  • Loading branch information
5 people authored Aug 6, 2021
1 parent 7214e4f commit 5913c10
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 92 deletions.
5 changes: 4 additions & 1 deletion pkg/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (s *testServer) GracefulStop(ctx context.Context) error {
func (s *testServer) Info() *server.ServiceInfo {
return &server.ServiceInfo{}
}
func (s *testServer) Healthz() bool {
return true
}

var errTest = fmt.Errorf("test error")

Expand Down Expand Up @@ -222,7 +225,7 @@ func TestApplication_Serve(t *testing.T) {
grpcConfig := xgrpc.DefaultConfig()
grpcConfig.Port = 0
app.initialize()
err := app.Serve(grpcConfig.Build())
err := app.Serve(grpcConfig.MustBuild())
So(err, ShouldBeNil)
go func() {
// make sure Serve() is called
Expand Down
11 changes: 7 additions & 4 deletions pkg/client/etcdv3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package etcdv3

import (
"context"
"testing"
"time"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/clientv3/concurrency"
"github.com/stretchr/testify/assert"
"testing"
"time"
)

func Test_GetKeyValue(t *testing.T) {
config := DefaultConfig()
config.Endpoints = []string{"127.0.0.1:2379"}
config.TTL = 5
etcdCli := newClient(config)
etcdCli, err := newClient(config)
assert.Nil(t, err)

ctx := context.TODO()

Expand All @@ -34,7 +36,8 @@ func Test_MutexLock(t *testing.T) {
config := DefaultConfig()
config.Endpoints = []string{"127.0.0.1:2379"}
config.TTL = 10
etcdCli := newClient(config)
etcdCli, err := newClient(config)
assert.Nil(t, err)

etcdMutex1, err := etcdCli.NewMutex("/test/lock",
concurrency.WithTTL(int(config.TTL)))
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/etcdv3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,11 @@ func (config *Config) MustBuild() *Client {
=======
>>>>>>> master
}

func (config *Config) MustBuild() *Client {
client, err := config.Build()
if err != nil {
xlog.Panicf("build etcd client failed: %v", err)
}
return client
}
Binary file added pkg/conf/datasource/apollo/.SampleApp_default
Binary file not shown.
6 changes: 4 additions & 2 deletions pkg/registry/etcdv3/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ func Test_etcdv3Registry(t *testing.T) {
func Test_etcdv3registry_UpdateAddressList(t *testing.T) {
etcdConfig := etcdv3.DefaultConfig()
etcdConfig.Endpoints = []string{"127.0.0.1:2379"}
reg := newETCDRegistry(&Config{
reg, err := newETCDRegistry(&Config{
Config: etcdConfig,
ReadTimeout: time.Second * 10,
Prefix: "jupiter",
logger: xlog.DefaultLogger,
})

assert.Nil(t, err)

var routeConfig = registry.RouteConfig{
ID: "1",
Scheme: "grpc",
Expand All @@ -117,7 +119,7 @@ func Test_etcdv3registry_UpdateAddressList(t *testing.T) {
},
},
}
_, err := reg.client.Put(context.Background(), "/jupiter/service_1/configurators/grpc:///routes/1", routeConfig.String())
_, err = reg.client.Put(context.Background(), "/jupiter/service_1/configurators/grpc:///routes/1", routeConfig.String())
assert.Nil(t, err)
ctx, cancel := context.WithCancel(context.Background())
go func() {
Expand Down
13 changes: 0 additions & 13 deletions pkg/sentinel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ import (

const ModuleName = "sentinel"

func Load(name string, opts ...conf.LoadOption) *Config {
var options = conf.DefaultLoadOptions(ModuleName)
for _, opt := range opts {
opt(&options)
}

var config = DefaultConfig()
if err := conf.UnmarshalKey(options.KeyPath(name), config); err != nil {
xlog.Panic("unmarshal key", xlog.Any("err", err))
}
return config
}

// StdConfig ...
func StdConfig(name string) *Config {
return RawConfig("jupiter.sentinel." + name)
Expand Down
52 changes: 0 additions & 52 deletions pkg/server/xecho/swagger/swagger.go

This file was deleted.

16 changes: 0 additions & 16 deletions pkg/server/xecho/swagger/swagger_test.go

This file was deleted.

7 changes: 4 additions & 3 deletions pkg/server/xgrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"testing"
"time"

"github.com/arschles/assert"
"github.com/douyu/jupiter/pkg/constant"
"github.com/douyu/jupiter/pkg/xlog"
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -59,8 +59,9 @@ func TestServer_Closed(t *testing.T) {
convey.Convey("test server stop", t, func() {
config := DefaultConfig()
config.Port = 0
ns := newServer(config)
err := ns.Stop()
ns, err := newServer(config)
assert.Nil(t, err)
err = ns.Stop()
convey.So(err, convey.ShouldBeNil)
err = ns.Serve()
convey.So(err, convey.ShouldEqual, grpc.ErrServerStopped)
Expand Down
1 change: 1 addition & 0 deletions pkg/util/xfile/lock_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

// +build windows

package xfile

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/worker/xcron/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func newETCDXcron(config *Config) {
config.logger = xlog.DefaultLogger
}
config.logger = config.logger.With(xlog.FieldMod(ecode.ModXcronETCD), xlog.FieldAddrAny(config.Config.Endpoints))
config.client = config.Config.Build()
config.client = config.Config.MustBuild()
if config.TTL == 0 {
config.TTL = DefaultTTL
}
Expand Down

0 comments on commit 5913c10

Please sign in to comment.