mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #125908 from aojea/race_pforward
fix race on integration test for portforward
This commit is contained in:
commit
cf33bef284
@ -113,7 +113,15 @@ func TestPortforward(t *testing.T) {
|
|||||||
// local port missing asks os to find random open port.
|
// local port missing asks os to find random open port.
|
||||||
// Example: ":8000" (local = random, remote = 8000)
|
// Example: ":8000" (local = random, remote = 8000)
|
||||||
localRemotePort := fmt.Sprintf(":%s", remotePort)
|
localRemotePort := fmt.Sprintf(":%s", remotePort)
|
||||||
streams, _, out, errOut := genericiooptions.NewTestIOStreams()
|
out := &mBuffer{
|
||||||
|
buffer: bytes.Buffer{},
|
||||||
|
}
|
||||||
|
errOut := &bytes.Buffer{}
|
||||||
|
streams := genericiooptions.IOStreams{
|
||||||
|
In: &bytes.Buffer{},
|
||||||
|
Out: out,
|
||||||
|
ErrOut: errOut,
|
||||||
|
}
|
||||||
portForwardOptions := portforward.NewDefaultPortForwardOptions(streams)
|
portForwardOptions := portforward.NewDefaultPortForwardOptions(streams)
|
||||||
portForwardOptions.Namespace = "default"
|
portForwardOptions.Namespace = "default"
|
||||||
portForwardOptions.PodName = "mypod"
|
portForwardOptions.PodName = "mypod"
|
||||||
@ -226,3 +234,20 @@ func (d *dummyPortForwarder) PortForward(ctx context.Context, name string, uid t
|
|||||||
resp.Write(stream) //nolint:errcheck
|
resp.Write(stream) //nolint:errcheck
|
||||||
return stream.Close()
|
return stream.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mBuffer struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
buffer bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *mBuffer) Write(p []byte) (n int, err error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.buffer.Write(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *mBuffer) String() string {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
return s.buffer.String()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user