Skip to content

Commit d0f7841

Browse files
akkwseefloodJervyShi
authored
fix: Publish subscription caused by metadata does not fill in caused … (#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]>
1 parent 81daaa9 commit d0f7841

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/runtime/runtime.go

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ func (m *MosnRuntime) initPubSubs(factorys ...*runtime_pubsub.Factory) error {
339339
// check consumerID
340340
consumerID := strings.TrimSpace(config.Metadata["consumerID"])
341341
if consumerID == "" {
342+
if config.Metadata == nil {
343+
config.Metadata = make(map[string]string)
344+
}
342345
config.Metadata["consumerID"] = m.runtimeConfig.AppManagement.AppId
343346
}
344347
// init this component with the config

pkg/runtime/runtime_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,32 @@ func TestMosnRuntime_initPubSubs(t *testing.T) {
294294
})
295295
}
296296

297+
func TestMosnRuntime_initPubSubsNotExistMetadata(t *testing.T) {
298+
t.Run("normal", func(t *testing.T) {
299+
// mock pubsub component
300+
mockPubSub := mock_pubsub.NewMockPubSub(gomock.NewController(t))
301+
mockPubSub.EXPECT().Init(gomock.Any()).Return(nil)
302+
f := func() pubsub.PubSub {
303+
return mockPubSub
304+
}
305+
306+
cfg := &MosnRuntimeConfig{
307+
PubSubManagement: map[string]mpubsub.Config{
308+
"mock": {},
309+
},
310+
}
311+
// construct MosnRuntime
312+
m := NewMosnRuntime(cfg)
313+
m.errInt = func(err error, format string, args ...interface{}) {
314+
log.DefaultLogger.Errorf("[runtime] occurs an error: "+err.Error()+", "+format, args...)
315+
}
316+
// test initPubSubs
317+
err := m.initPubSubs(mpubsub.NewFactory("mock", f))
318+
// assert result
319+
assert.Nil(t, err)
320+
})
321+
}
322+
297323
func TestMosnRuntime_initStates(t *testing.T) {
298324
t.Run("init success", func(t *testing.T) {
299325
// prepare mock

0 commit comments

Comments
 (0)