Skip to content

Commit

Permalink
fix: make ut deterministic (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeflood authored Feb 24, 2022
1 parent d008d41 commit 19826f7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
10 changes: 1 addition & 9 deletions components/configstores/apollo/change_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/zouyx/agollo/v4/storage"
"mosn.io/layotto/components/configstores"
"mosn.io/pkg/log"
"mosn.io/pkg/utils"
"time"
)

Expand Down Expand Up @@ -73,14 +72,7 @@ func (lis *changeListener) notify(s *subscriber, keyWithLabel string, change *st
log.DefaultLogger.Errorf("panic when notify subscriber. %v", r)
// make sure unused chan are all deleted
if lis != nil && lis.subscribers != nil {
utils.GoWithRecover(func() {
defer func() {
if r := recover(); r != nil {
log.DefaultLogger.Errorf("panic when removing subscribers after panic. %v", r)
}
}()
lis.subscribers.remove(s)
}, nil)
lis.subscribers.remove(s)
}
}
}()
Expand Down
1 change: 1 addition & 0 deletions components/configstores/apollo/change_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func Test_changeListener_writeToClosedChan(t *testing.T) {
Changes: changes,
}
event.Namespace = ns
// execute
lis.OnChange(event)
// assert no panic
}
1 change: 1 addition & 0 deletions components/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.10.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ=
github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
Expand Down
2 changes: 1 addition & 1 deletion components/rpc/invoker/mosn/channel/xchannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func init() {
func newXChannel(config ChannelConfig) (rpc.Channel, error) {
proto := transport_protocol.GetProtocol(config.Protocol)
if proto == nil {
return nil, fmt.Errorf("protocol %s not found", proto)
return nil, fmt.Errorf("protocol %s not found", config.Protocol)
}
if err := proto.Init(config.Ext); err != nil {
return nil, err
Expand Down
10 changes: 9 additions & 1 deletion components/rpc/invoker/mosn/channel/xchannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,22 @@ func TestChannel(t *testing.T) {
assert.Equal(t, "ok", string(resp.Data))
}

func TestInvalidProtocal(t *testing.T) {
config := ChannelConfig{Size: 1, Protocol: "dubbogo", Ext: map[string]interface{}{"class": "xxx"}}
_, err := newXChannel(config)
assert.NotNil(t, err)

assert.Equal(t, err.Error(), "protocol dubbogo not found")
}

func TestChannelTimeout(t *testing.T) {
startTestServer()

config := ChannelConfig{Size: 1, Protocol: proto, Ext: map[string]interface{}{"class": "xxx"}}
channel, err := newXChannel(config)
assert.Nil(t, err)

req := &rpc.RPCRequest{Ctx: context.TODO(), Id: "foo", Method: "bar", Data: []byte("timeout"), Timeout: 500}
req := &rpc.RPCRequest{Ctx: context.TODO(), Id: "foo", Method: "bar", Data: []byte("timeout"), Timeout: 990}
_, err = channel.Do(req)
t.Log(err)
assert.True(t, strings.Contains(err.Error(), ErrTimeout.Error()))
Expand Down

0 comments on commit 19826f7

Please sign in to comment.