diff --git a/api/internal/consumer/mock.go b/api/internal/consumer/mock.go index d25c29dc..9d44e126 100644 --- a/api/internal/consumer/mock.go +++ b/api/internal/consumer/mock.go @@ -74,3 +74,14 @@ func (p *filterPlugin) Factory() api.FilterFactory { func (p *filterPlugin) Config() api.PluginConfig { return &Config{} } + +type MockConsumer struct { +} + +func (c *MockConsumer) Name() string { + return "mock" +} + +func (c *MockConsumer) PluginConfig(_ string) api.PluginConsumerConfig { + return &ConsumerConfig{} +} diff --git a/api/pkg/filtermanager/api_impl.go b/api/pkg/filtermanager/api_impl.go index 71148560..574f9a6c 100644 --- a/api/pkg/filtermanager/api_impl.go +++ b/api/pkg/filtermanager/api_impl.go @@ -160,7 +160,10 @@ func (cb *filterManagerCallbackHandler) Reset() { // We don't reset namespace, as filterManager will only be reused in the same route, // which must have the same namespace. cb.consumer = nil + cb.pluginState = nil cb.streamInfo = nil + cb.logArgNames = "" + cb.logArgs = nil cb.cacheLock.Unlock() } diff --git a/api/pkg/filtermanager/api_impl_test.go b/api/pkg/filtermanager/api_impl_test.go index 66dfedb3..c9398deb 100644 --- a/api/pkg/filtermanager/api_impl_test.go +++ b/api/pkg/filtermanager/api_impl_test.go @@ -24,6 +24,7 @@ import ( "github.com/agiledragon/gomonkey/v2" "github.com/stretchr/testify/assert" + "mosn.io/htnn/api/internal/consumer" "mosn.io/htnn/api/pkg/filtermanager/api" "mosn.io/htnn/api/pkg/filtermanager/model" "mosn.io/htnn/api/plugins/tests/pkg/envoy" @@ -233,3 +234,26 @@ func TestLogWithArgs(t *testing.T) { assert.Equal(t, []any{0, 1, 2}, fmtArgs[level+"f"]) } } + +func TestReset(t *testing.T) { + cb := &filterManagerCallbackHandler{ + FilterCallbackHandler: envoy.NewCAPIFilterCallbackHandler(), + } + cb.SetConsumer(&consumer.MockConsumer{}) + cb.PluginState() + cb.StreamInfo() + cb.WithLogArg("k", "v") + + assert.NotNil(t, cb.consumer) + assert.NotNil(t, cb.pluginState) + assert.NotNil(t, cb.streamInfo) + assert.NotEqual(t, "", cb.logArgNames) + assert.NotNil(t, cb.logArgs) + + cb.Reset() + assert.Nil(t, cb.consumer) + assert.Nil(t, cb.pluginState) + assert.Nil(t, cb.streamInfo) + assert.Equal(t, "", cb.logArgNames) + assert.Nil(t, cb.logArgs) +}