Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Data Race in portforward e2e test of EventListener #631

Merged
merged 1 commit into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions test/buffer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// +build e2e

/*
Copyright 2019 The Tekton Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package test

import (
"bytes"
"sync"
)

// Buffer is the thread safe Buffer implementation
type Buffer struct {
b bytes.Buffer
m sync.Mutex
}

// Write to the Buffer in a thread safe manner
func (b *Buffer) Write(p []byte) (n int, err error) {
b.m.Lock()
defer b.m.Unlock()
return b.b.Write(p)
}

// String returns the contents of the unread portion of the buffer
// as a string in a thread safe manner.
func (b *Buffer) String() string {
b.m.Lock()
defer b.m.Unlock()
return b.b.String()
}
2 changes: 1 addition & 1 deletion test/eventlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func TestEventListenerCreate(t *testing.T) {
hostIP := strings.TrimPrefix(config.Host, "https://")
serverURL := url.URL{Scheme: "https", Path: path, Host: hostIP}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: roundTripper}, http.MethodPost, &serverURL)
out, errOut := new(bytes.Buffer), new(bytes.Buffer)
out, errOut := new(Buffer), new(Buffer)
readyChan := make(chan struct{}, 1)
forwarder, err := portforward.New(dialer, []string{portString}, stopChan, readyChan, out, errOut)
if err != nil {
Expand Down