Merge pull request #125908 from aojea/race_pforward
fix race on integration test for portforward
This commit is contained in:
		@@ -113,7 +113,15 @@ func TestPortforward(t *testing.T) {
 | 
			
		||||
	// local port missing asks os to find random open port.
 | 
			
		||||
	// Example: ":8000" (local = random, remote = 8000)
 | 
			
		||||
	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.Namespace = "default"
 | 
			
		||||
	portForwardOptions.PodName = "mypod"
 | 
			
		||||
@@ -226,3 +234,20 @@ func (d *dummyPortForwarder) PortForward(ctx context.Context, name string, uid t
 | 
			
		||||
	resp.Write(stream) //nolint:errcheck
 | 
			
		||||
	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()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user