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

build: enable '-race' for 'go test' #250

Merged
merged 2 commits into from
Mar 21, 2022
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ generate-%: controller-gen
# Run tests
KUBEBUILDER_ASSETS?="$(shell $(ENVTEST) --arch=$(ENVTEST_ARCH) use -i $(ENVTEST_KUBERNETES_VERSION) --bin-dir=$(ENVTEST_ASSETS_DIR) -p path)"
test-%: tidy-% generate-% fmt-% vet-% install-envtest
cd $(subst :,/,$*); KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -coverprofile cover.out
cd $(subst :,/,$*); KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test ./... -race -coverprofile cover.out

release-%:
$(eval REL_PATH=$(subst :,/,$*))
Expand Down
21 changes: 18 additions & 3 deletions gittestserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net/url"
"os"
"path/filepath"
"sync"
"time"

"github.com/go-git/go-billy/v5/memfs"
Expand All @@ -36,6 +37,8 @@ import (
"github.com/sosedoff/gitkit"
)

var m sync.RWMutex

// NewTempGitServer returns a GitServer with a newly created temp
// dir as repository docroot.
func NewTempGitServer() (*GitServer, error) {
Expand Down Expand Up @@ -188,12 +191,20 @@ func (s *GitServer) StopHTTP() {
// unlike StartSSH(), and the server URL is available with
// SSHAddress() after calling this.
func (s *GitServer) ListenSSH() error {
if s.sshServer == nil {
m.RLock()
sshServer := s.sshServer
m.RUnlock()

if sshServer == nil {
m.Lock()
defer m.Unlock()
s.sshServer = gitkit.NewSSH(s.config)

// This is where authentication would happen, when needed.
s.sshServer.PublicKeyLookupFunc = func(content string) (*gitkit.PublicKey, error) {
return &gitkit.PublicKey{Id: "test-user"}, nil
}

// :0 should result in an OS assigned free port; 127.0.0.1
// forces the lowest common denominator of TCPv4 on localhost.
return s.sshServer.Listen("127.0.0.1:0")
Expand All @@ -216,8 +227,12 @@ func (s *GitServer) StartSSH() error {

// StopSSH stops the SSH git server.
func (s *GitServer) StopSSH() error {
if s.sshServer != nil {
return s.sshServer.Stop()
m.RLock()
sshServer := s.sshServer
m.RUnlock()

if sshServer != nil {
return sshServer.Stop()
}
return nil
}
Expand Down