Skip to content

Commit 74c1b27

Browse files
committed
fix test
Signed-off-by: spacewander <[email protected]>
1 parent 7a4602e commit 74c1b27

File tree

11 files changed

+372
-101
lines changed

11 files changed

+372
-101
lines changed

api/internal/consumer/consumer.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ type Consumer struct {
4545
FilterConfigs map[string]*fmModel.ParsedFilterConfig
4646

4747
// fields that generated from the configuration
48-
CanSkipMethod map[string]bool
49-
FilterNames []string
50-
InitOnce sync.Once
48+
CanSkipMethod map[string]bool
49+
FilterNames []string
50+
InitOnce sync.Once
51+
CanSkipMethodOnce sync.Once
5152
}
5253

5354
func (c *Consumer) Unmarshal(s string) error {

api/internal/consumer/consumer_manager.go

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ func UpdateConsumers(value *structpb.Struct) {
4848
currValue, ok := currIdx[name]
4949
if !ok || currValue.generation != v {
5050
s := fields["d"].GetStringValue()
51+
api.LogInfof("receive consumer configuration: %s", s)
52+
5153
var c Consumer
5254
err := c.Unmarshal(s)
5355
if err != nil {

api/internal/consumer/consumer_manager_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"mosn.io/htnn/api/pkg/consumer/model"
2424
"mosn.io/htnn/api/pkg/plugins"
25+
_ "mosn.io/htnn/api/plugins/tests/pkg/envoy" // for log implementation
2526
)
2627

2728
type consumerTest struct {

api/pkg/filtermanager/filtermanager.go

+18-14
Original file line numberDiff line numberDiff line change
@@ -601,34 +601,21 @@ func (m *filterManager) DecodeHeaders(headers capi.RequestHeaderMap, endStream b
601601

602602
if len(c.FilterConfigs) > 0 {
603603
c.InitOnce.Do(func() {
604-
canSkipMethod := newSkipMethodsMap()
605604
names := make([]string, 0, len(c.FilterConfigs))
606605
for name, fc := range c.FilterConfigs {
607606
names = append(names, name)
608607

609-
factory := fc.Factory
610608
config := fc.ParsedConfig
611609
if initer, ok := config.(pkgPlugins.Initer); ok {
612610
// For now, we have nothing to provide as config callbacks
613611
err := initer.Init(nil)
614612
if err != nil {
615-
factory = NewInternalErrorFactory(fc.Name, err)
613+
fc.Factory = NewInternalErrorFactory(fc.Name, err)
616614
}
617615
}
618-
619-
f := factory(config, m.callbacks)
620-
for meth := range canSkipMethod {
621-
overridden, err := reflectx.IsMethodOverridden(f, meth)
622-
if err != nil {
623-
api.LogErrorf("failed to check method %s in filter: %v", meth, err)
624-
// canSkipMethod[meth] will be false
625-
}
626-
canSkipMethod[meth] = canSkipMethod[meth] && !overridden
627-
}
628616
}
629617

630618
c.FilterNames = names
631-
c.CanSkipMethod = canSkipMethod
632619
})
633620

634621
filterWrappers := make([]*model.FilterWrapper, len(c.FilterConfigs))
@@ -640,6 +627,23 @@ func (m *filterManager) DecodeHeaders(headers capi.RequestHeaderMap, endStream b
640627
filterWrappers[i] = model.NewFilterWrapper(name, f)
641628
}
642629

630+
c.CanSkipMethodOnce.Do(func() {
631+
canSkipMethod := newSkipMethodsMap()
632+
for _, fw := range filterWrappers {
633+
f := fw.Filter
634+
for meth := range canSkipMethod {
635+
overridden, err := reflectx.IsMethodOverridden(f, meth)
636+
if err != nil {
637+
api.LogErrorf("failed to check method %s in filter: %v", meth, err)
638+
// canSkipMethod[meth] will be false
639+
}
640+
canSkipMethod[meth] = canSkipMethod[meth] && !overridden
641+
}
642+
}
643+
644+
c.CanSkipMethod = canSkipMethod
645+
})
646+
643647
canSkipMethod := c.CanSkipMethod
644648
m.canSkipDecodeData = m.canSkipDecodeData && canSkipMethod["DecodeData"] && canSkipMethod["DecodeRequest"]
645649
m.canSkipEncodeHeaders = m.canSkipEncodeData && canSkipMethod["EncodeHeaders"]

api/pkg/plugins/plugins_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"google.golang.org/protobuf/types/known/anypb"
2525

2626
"mosn.io/htnn/api/pkg/filtermanager/api"
27-
_ "mosn.io/htnn/api/plugins/tests/pkg/envoy"
27+
_ "mosn.io/htnn/api/plugins/tests/pkg/envoy" // for log implementation
2828
)
2929

3030
func TestIterateHttpPlugin(t *testing.T) {

api/plugins/tests/integration/config.pb.go

+69-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/plugins/tests/integration/config.pb.validate.go

+102
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/plugins/tests/integration/config.proto

+4
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ message BadPluginConfig {
3131
bool panic_in_parse = 2;
3232
bool error_in_init = 3;
3333
}
34+
35+
message ConsumerConfig {
36+
string name = 1;
37+
}

0 commit comments

Comments
 (0)