Skip to content

Commit

Permalink
fix: Publish subscription caused by metadata does not fill in caused … (
Browse files Browse the repository at this point in the history
mosn#524)

* fix: Publish subscription caused by metadata does not fill in caused by painc

* Supplement pubsub unit tests

Co-authored-by: seeflood <[email protected]>
Co-authored-by: JervyShi <[email protected]>
  • Loading branch information
3 people authored May 3, 2022
1 parent 81daaa9 commit d0f7841
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ func (m *MosnRuntime) initPubSubs(factorys ...*runtime_pubsub.Factory) error {
// check consumerID
consumerID := strings.TrimSpace(config.Metadata["consumerID"])
if consumerID == "" {
if config.Metadata == nil {
config.Metadata = make(map[string]string)
}
config.Metadata["consumerID"] = m.runtimeConfig.AppManagement.AppId
}
// init this component with the config
Expand Down
26 changes: 26 additions & 0 deletions pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,32 @@ func TestMosnRuntime_initPubSubs(t *testing.T) {
})
}

func TestMosnRuntime_initPubSubsNotExistMetadata(t *testing.T) {
t.Run("normal", func(t *testing.T) {
// mock pubsub component
mockPubSub := mock_pubsub.NewMockPubSub(gomock.NewController(t))
mockPubSub.EXPECT().Init(gomock.Any()).Return(nil)
f := func() pubsub.PubSub {
return mockPubSub
}

cfg := &MosnRuntimeConfig{
PubSubManagement: map[string]mpubsub.Config{
"mock": {},
},
}
// construct MosnRuntime
m := NewMosnRuntime(cfg)
m.errInt = func(err error, format string, args ...interface{}) {
log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...)
}
// test initPubSubs
err := m.initPubSubs(mpubsub.NewFactory("mock", f))
// assert result
assert.Nil(t, err)
})
}

func TestMosnRuntime_initStates(t *testing.T) {
t.Run("init success", func(t *testing.T) {
// prepare mock
Expand Down

0 comments on commit d0f7841

Please sign in to comment.