Skip to content

Commit 62032ba

Browse files
committed
🏃 Run tests with race detector enabled
1 parent bb96678 commit 62032ba

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

hack/test-all.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ setup_envs
2222

2323
header_text "running go test"
2424

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

2827
header_text "running coverage"
2928

pkg/builder/controller_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"strings"
23+
"sync/atomic"
2324

2425
. "github.com/onsi/ginkgo"
2526
. "github.com/onsi/gomega"
@@ -214,7 +215,7 @@ var _ = Describe("application", func() {
214215
var (
215216
deployPrctExecuted = false
216217
replicaSetPrctExecuted = false
217-
allPrctExecuted = 0
218+
allPrctExecuted = int64(0)
218219
)
219220

220221
deployPrct := predicate.Funcs{
@@ -246,7 +247,7 @@ var _ = Describe("application", func() {
246247
BeAssignableToTypeOf(&appsv1.ReplicaSet{}),
247248
))
248249

249-
allPrctExecuted++
250+
atomic.AddInt64(&allPrctExecuted, 1)
250251
return true
251252
},
252253
}

pkg/cache/informer_cache_unit_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
corev1 "k8s.io/api/core/v1"
88
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
9+
"k8s.io/apimachinery/pkg/runtime"
910
"k8s.io/apimachinery/pkg/runtime/schema"
1011
"k8s.io/client-go/kubernetes/scheme"
1112

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

6061
It("should find the object type of a list with a slice of pointers items field", func() {
6162
By("registering the type", func() {
63+
ip.Scheme = runtime.NewScheme()
6264
err := (&crscheme.Builder{
6365
GroupVersion: schema.GroupVersion{Group: itemPointerSliceTypeGroupName, Version: itemPointerSliceTypeVersion},
6466
}).
6567
Register(
6668
&controllertest.UnconventionalListType{},
6769
&controllertest.UnconventionalListTypeList{},
68-
).AddToScheme(scheme.Scheme)
70+
).AddToScheme(ip.Scheme)
6971
Expect(err).To(BeNil())
7072
})
7173

pkg/internal/testing/integration/internal/integration_tests/etcd_integration_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ var _ = Describe("Etcd", func() {
3939
}
4040

4141
Expect(etcd.Start()).To(Succeed())
42-
defer func() {
43-
Expect(etcd.Stop()).To(Succeed())
44-
}()
42+
Expect(etcd.Stop()).To(Succeed())
4543

4644
Expect(stderr.String()).NotTo(BeEmpty())
4745
})

pkg/internal/testing/integration/internal/process_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ var _ = Describe("Start method", func() {
216216
processState.StartTimeout = 1 * time.Second
217217

218218
Expect(processState.Start(stdout, stderr)).To(Succeed())
219+
Expect(processState.Session).Should(gexec.Exit())
219220

220221
Expect(stdout.String()).To(Equal("that is stdout\n"))
221222
Expect(stderr.String()).To(Equal("this is stderr\ni started\n"))

pkg/manager/manager_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import (
2121
"io/ioutil"
2222
"net"
2323
"net/http"
24+
"os"
2425
rt "runtime"
26+
"runtime/pprof"
2527

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

201-
By("Expect second manager to lose leader election")
203+
m2Stop := make(chan struct{})
204+
m2done := make(chan struct{})
202205
go func() {
203206
defer GinkgoRecover()
204-
Expect(m2.Start(stop)).NotTo(HaveOccurred())
205-
Consistently(m2.Elected()).ShouldNot(Receive())
207+
Expect(m2.Start(m2Stop)).NotTo(HaveOccurred())
208+
close(m2done)
206209
}()
210+
Consistently(m2.Elected()).ShouldNot(Receive())
207211

208-
By("Expect controller on manager without leader lease never to run")
209212
Consistently(c2).ShouldNot(Receive())
213+
close(m2Stop)
214+
<-m2done
210215
})
211216

212217
It("should return an error if namespace not set and not running in cluster", func() {
@@ -837,19 +842,21 @@ var _ = Describe("manger.Manager", func() {
837842
})
838843
})
839844

840-
It("should not leak goroutines when stop", func(done Done) {
845+
FIt("should not leak goroutines when stop", func(done Done) {
841846
// TODO(directxman12): After closing the proper leaks on watch this must be reduced to 0
842847
// The leaks currently come from the event-related code (as in corev1.Event).
843848
threshold := 3
844849

845850
m, err := New(cfg, Options{})
846851
Expect(err).NotTo(HaveOccurred())
847852
startGoruntime := rt.NumGoroutine()
853+
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
848854

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

859+
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
853860
Expect(rt.NumGoroutine() - startGoruntime).To(BeNumerically("<=", threshold))
854861
close(done)
855862
})

0 commit comments

Comments
 (0)