Skip to content

🏃 Run tests with race detector enabled #1012

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

Merged
merged 1 commit into from
Jul 13, 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
3 changes: 1 addition & 2 deletions hack/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ setup_envs

header_text "running go test"

# TODO(directxman12): enable the race detector once the LeaderElector race condition is resolved in client-go
go test ${MOD_OPT} ./... -parallel 4
go test -race ${MOD_OPT} ./... -parallel 4

header_text "running coverage"

Expand Down
5 changes: 3 additions & 2 deletions pkg/builder/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"strings"
"sync/atomic"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -214,7 +215,7 @@ var _ = Describe("application", func() {
var (
deployPrctExecuted = false
replicaSetPrctExecuted = false
allPrctExecuted = 0
allPrctExecuted = int64(0)
)

deployPrct := predicate.Funcs{
Expand Down Expand Up @@ -246,7 +247,7 @@ var _ = Describe("application", func() {
BeAssignableToTypeOf(&appsv1.ReplicaSet{}),
))

allPrctExecuted++
atomic.AddInt64(&allPrctExecuted, 1)
return true
},
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cache/informer_cache_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"

Expand Down Expand Up @@ -59,13 +60,14 @@ var _ = Describe("ip.objectTypeForListObject", func() {

It("should find the object type of a list with a slice of pointers items field", func() {
By("registering the type", func() {
ip.Scheme = runtime.NewScheme()
err := (&crscheme.Builder{
GroupVersion: schema.GroupVersion{Group: itemPointerSliceTypeGroupName, Version: itemPointerSliceTypeVersion},
}).
Register(
&controllertest.UnconventionalListType{},
&controllertest.UnconventionalListTypeList{},
).AddToScheme(scheme.Scheme)
).AddToScheme(ip.Scheme)
Expect(err).To(BeNil())
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ var _ = Describe("Etcd", func() {
}

Expect(etcd.Start()).To(Succeed())
defer func() {
Expect(etcd.Stop()).To(Succeed())
}()
Expect(etcd.Stop()).To(Succeed())

Expect(stderr.String()).NotTo(BeEmpty())
})
Expand Down
1 change: 1 addition & 0 deletions pkg/internal/testing/integration/internal/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ var _ = Describe("Start method", func() {
processState.StartTimeout = 1 * time.Second

Expect(processState.Start(stdout, stderr)).To(Succeed())
Expect(processState.Session).Should(gexec.Exit())

Expect(stdout.String()).To(Equal("that is stdout\n"))
Expect(stderr.String()).To(Equal("this is stderr\ni started\n"))
Expand Down
15 changes: 11 additions & 4 deletions pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"io/ioutil"
"net"
"net/http"
"os"
rt "runtime"
"runtime/pprof"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -198,15 +200,18 @@ var _ = Describe("manger.Manager", func() {
return nil
}))).To(Succeed())

By("Expect second manager to lose leader election")
m2Stop := make(chan struct{})
m2done := make(chan struct{})
go func() {
defer GinkgoRecover()
Expect(m2.Start(stop)).NotTo(HaveOccurred())
Consistently(m2.Elected()).ShouldNot(Receive())
Expect(m2.Start(m2Stop)).NotTo(HaveOccurred())
close(m2done)
}()
Consistently(m2.Elected()).ShouldNot(Receive())

By("Expect controller on manager without leader lease never to run")
Consistently(c2).ShouldNot(Receive())
close(m2Stop)
<-m2done
})

It("should return an error if namespace not set and not running in cluster", func() {
Expand Down Expand Up @@ -845,11 +850,13 @@ var _ = Describe("manger.Manager", func() {
m, err := New(cfg, Options{})
Expect(err).NotTo(HaveOccurred())
startGoruntime := rt.NumGoroutine()
_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test here is apparently flaky with -race set. I am not sure if we can fix this, but having the dump here will at least give some clues.

I am unfortunately not able to repro the issue on my computer, that's why I left this here.


s := make(chan struct{})
close(s)
Expect(m.Start(s)).NotTo(HaveOccurred())

_ = pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
Expect(rt.NumGoroutine() - startGoruntime).To(BeNumerically("<=", threshold))
close(done)
})
Expand Down