mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Move some test-only code into the test
This commit is contained in:
parent
20826e6d50
commit
a559d8d9b2
@ -317,15 +317,6 @@ func NewProxier(loadBalancer LoadBalancer, address string) *Proxier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopProxy stops the proxy for the named service.
|
|
||||||
func (proxier *Proxier) StopProxy(service string) error {
|
|
||||||
info, found := proxier.getServiceInfo(service)
|
|
||||||
if !found {
|
|
||||||
return fmt.Errorf("unknown service: %s", service)
|
|
||||||
}
|
|
||||||
return proxier.stopProxy(service, info)
|
|
||||||
}
|
|
||||||
|
|
||||||
// This assumes proxier.mu is not locked.
|
// This assumes proxier.mu is not locked.
|
||||||
func (proxier *Proxier) stopProxy(service string, info *serviceInfo) error {
|
func (proxier *Proxier) stopProxy(service string, info *serviceInfo) error {
|
||||||
proxier.mu.Lock()
|
proxier.mu.Lock()
|
||||||
|
@ -171,6 +171,15 @@ func TestUDPProxy(t *testing.T) {
|
|||||||
testEchoUDP(t, "127.0.0.1", proxyPort)
|
testEchoUDP(t, "127.0.0.1", proxyPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper: Stops the proxy for the named service.
|
||||||
|
func stopProxyByName(proxier *Proxier, service string) error {
|
||||||
|
info, found := proxier.getServiceInfo(service)
|
||||||
|
if !found {
|
||||||
|
return fmt.Errorf("unknown service: %s", service)
|
||||||
|
}
|
||||||
|
return proxier.stopProxy(service, info)
|
||||||
|
}
|
||||||
|
|
||||||
func TestTCPProxyStop(t *testing.T) {
|
func TestTCPProxyStop(t *testing.T) {
|
||||||
lb := NewLoadBalancerRR()
|
lb := NewLoadBalancerRR()
|
||||||
lb.OnUpdate([]api.Endpoints{
|
lb.OnUpdate([]api.Endpoints{
|
||||||
@ -192,7 +201,7 @@ func TestTCPProxyStop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
||||||
p.StopProxy("echo")
|
stopProxyByName(p, "echo")
|
||||||
// Wait for the port to really close.
|
// Wait for the port to really close.
|
||||||
if err := waitForClosedPortTCP(p, proxyPort); err != nil {
|
if err := waitForClosedPortTCP(p, proxyPort); err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
@ -220,7 +229,7 @@ func TestUDPProxyStop(t *testing.T) {
|
|||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
|
||||||
p.StopProxy("echo")
|
stopProxyByName(p, "echo")
|
||||||
// Wait for the port to really close.
|
// Wait for the port to really close.
|
||||||
if err := waitForClosedPortUDP(p, proxyPort); err != nil {
|
if err := waitForClosedPortUDP(p, proxyPort); err != nil {
|
||||||
t.Fatalf(err.Error())
|
t.Fatalf(err.Error())
|
||||||
|
Loading…
Reference in New Issue
Block a user