Skip to content

Commit a58a624

Browse files
committed
fix ut
1 parent 74546e8 commit a58a624

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

pkg/manager/controllers/circuitbreaker/event_handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func matchChangedBreakers(c client.Reader, old, new *v1.Pod) ([]*ctrlmeshv1alpha
126126
}
127127
oldMatch := selector.Matches(labels.Set(old.Labels))
128128
newMatch := selector.Matches(labels.Set(new.Labels))
129-
if oldMatch == newMatch {
129+
if oldMatch != newMatch {
130130
res = append(res, &breakers.Items[i])
131131
}
132132
}

pkg/manager/controllers/faultinjection/event_handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func matchChangedFaults(c client.Reader, old, new *v1.Pod) ([]*ctrlmeshv1alpha1.
127127
}
128128
oldMatch := selector.Matches(labels.Set(old.Labels))
129129
newMatch := selector.Matches(labels.Set(new.Labels))
130-
if oldMatch == newMatch { // REMOVE: 为什么不是同时为true
130+
if oldMatch != newMatch {
131131
res = append(res, &faults.Items[i])
132132
}
133133
}

pkg/manager/controllers/faultinjection/faultinjection_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ var faultInjection = &ctrlmeshv1alpha1.FaultInjection{
107107
func TestFaultInjection(t *testing.T) {
108108
g := gomega.NewGomegaWithT(t)
109109
defer Stop()
110+
grpcserver.GrpcServerPort = 5455
110111
RunMockServer()
111112
testPod := mockPod.DeepCopy()
112113
testFaultInjection := faultInjection.DeepCopy()
@@ -198,7 +199,6 @@ func TestFaultInjection(t *testing.T) {
198199
return c.Get(ctx, types.NamespacedName{Name: "testfi", Namespace: "default"}, cb)
199200
}, 5*time.Second, 1*time.Second).Should(gomega.HaveOccurred())
200201
fmt.Println("test finished")
201-
202202
}
203203

204204
var faultManager faultinjection.ManagerInterface

pkg/proxy/grpcserver/server.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ import (
3535
)
3636

3737
var (
38-
grpcServerPort = constants.ProxyGRPCServerPort
38+
GrpcServerPort = constants.ProxyGRPCServerPort
3939
)
4040

4141
func init() {
4242
envConfig := os.Getenv(constants.EnvProxyGRPCServerPort)
4343
if envConfig != "" {
4444
p, err := strconv.Atoi(envConfig)
4545
if err != nil {
46-
grpcServerPort = p
46+
GrpcServerPort = p
4747
}
4848
}
4949
}
@@ -59,7 +59,7 @@ func (s *GrpcServer) Start(ctx context.Context) {
5959
s.mux = http.NewServeMux()
6060
s.mux.Handle(protoconnect.NewThrottlingHandler(&grpcThrottlingHandler{mgr: s.BreakerMgr}, connect.WithSendMaxBytes(1024*1024*64)))
6161
s.mux.Handle(protoconnect.NewFaultInjectHandler(&grpcFaultInjectHandler{mgr: s.FaultInjectionMgr}, connect.WithSendMaxBytes(1024*1024*64)))
62-
addr := fmt.Sprintf(":%d", grpcServerPort)
62+
addr := fmt.Sprintf(":%d", GrpcServerPort)
6363
go func() {
6464
// Use h2c so we can serve HTTP/2 without TLS.
6565
if err := http.ListenAndServe(addr, h2c.NewHandler(s.mux, &http2.Server{})); err != nil {

pkg/proxy/grpcserver/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
func TestServer(t *testing.T) {
3737
g := gomega.NewGomegaWithT(t)
3838
ctx := context.TODO()
39-
grpcServerPort = 8889
39+
GrpcServerPort = 8889
4040
breakerMgr := circuitbreaker.NewManager(ctx)
4141
proxyServer := &GrpcServer{BreakerMgr: breakerMgr}
4242
go proxyServer.Start(ctx)

0 commit comments

Comments
 (0)