Skip to content

Commit 3218a86

Browse files
committed
adjust tests
1 parent 3c5359d commit 3218a86

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pkg/certwatcher/certwatcher_test.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ var _ = Describe("CertWatcher", func() {
7777
Expect(err).ToNot(HaveOccurred())
7878
})
7979

80-
startWatcher := func() (done <-chan struct{}) {
80+
startWatcher := func(interval time.Duration) (done <-chan struct{}) {
8181
doneCh := make(chan struct{})
8282
go func() {
8383
defer GinkgoRecover()
8484
defer close(doneCh)
85-
Expect(watcher.WithWatchInterval(time.Second).Start(ctx)).To(Succeed())
85+
Expect(watcher.WithWatchInterval(interval).Start(ctx)).To(Succeed())
8686
}()
8787
// wait till we read first cert
8888
Eventually(func() error {
@@ -93,14 +93,16 @@ var _ = Describe("CertWatcher", func() {
9393
}
9494

9595
It("should read the initial cert/key", func() {
96-
doneCh := startWatcher()
96+
// This test verifies the initial read succeeded. So interval doesn't matter.
97+
doneCh := startWatcher(10 * time.Second)
9798

9899
ctxCancel()
99100
Eventually(doneCh, "4s").Should(BeClosed())
100101
})
101102

102103
It("should reload currentCert when changed", func() {
103-
doneCh := startWatcher()
104+
// This test verifies fsnotify detects the cert change. So interval doesn't matter.
105+
doneCh := startWatcher(10 * time.Second)
104106
called := atomic.Int64{}
105107
watcher.RegisterCallback(func(crt tls.Certificate) {
106108
called.Add(1)
@@ -124,7 +126,8 @@ var _ = Describe("CertWatcher", func() {
124126
})
125127

126128
It("should reload currentCert when changed with rename", func() {
127-
doneCh := startWatcher()
129+
// This test verifies fsnotify detects the cert change. So interval doesn't matter.
130+
doneCh := startWatcher(10 * time.Second)
128131
called := atomic.Int64{}
129132
watcher.RegisterCallback(func(crt tls.Certificate) {
130133
called.Add(1)
@@ -154,7 +157,8 @@ var _ = Describe("CertWatcher", func() {
154157
})
155158

156159
It("should reload currentCert after move out", func() {
157-
doneCh := startWatcher()
160+
// This test verifies poll works, so we'll use 1s as interval (fsnotify doesn't detect this change).
161+
doneCh := startWatcher(1 * time.Second)
158162
called := atomic.Int64{}
159163
watcher.RegisterCallback(func(crt tls.Certificate) {
160164
called.Add(1)
@@ -190,7 +194,8 @@ var _ = Describe("CertWatcher", func() {
190194
})
191195

192196
It("should get updated on successful certificate read", func() {
193-
doneCh := startWatcher()
197+
// This test verifies fsnotify, so interval doesn't matter.
198+
doneCh := startWatcher(10 * time.Second)
194199

195200
Eventually(func() error {
196201
readCertificateTotalAfter := testutil.ToFloat64(metrics.ReadCertificateTotal)
@@ -205,7 +210,8 @@ var _ = Describe("CertWatcher", func() {
205210
})
206211

207212
It("should get updated on read certificate errors", func() {
208-
doneCh := startWatcher()
213+
// This test works with fsnotify, so interval doesn't matter.
214+
doneCh := startWatcher(10 * time.Second)
209215

210216
Eventually(func() error {
211217
readCertificateTotalAfter := testutil.ToFloat64(metrics.ReadCertificateTotal)

0 commit comments

Comments
 (0)