Skip to content

Commit 253c568

Browse files
committed
test(remote): add unit test for healthcheck during creation of a new cluster accessor
Signed-off-by: Aljoscha Poertner <[email protected]>
1 parent 899b324 commit 253c568

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

controllers/remote/cluster_cache_healthcheck_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,32 @@ func TestClusterCacheHealthCheck(t *testing.T) {
146146
}, 5*time.Second, 1*time.Second).Should(BeTrue())
147147
})
148148

149+
t.Run("during creation of a new cluster accessor", func(t *testing.T) {
150+
g := NewWithT(t)
151+
ns := setup(t, g)
152+
defer teardown(t, g, ns)
153+
// Create a context with a timeout to cancel the healthcheck after some time
154+
ctx, cancel := context.WithTimeout(ctx, time.Second)
155+
defer cancel()
156+
// Delete the cluster accessor and lock the cluster to simulate creation of a new cluster accessor
157+
cct.deleteAccessor(ctx, testClusterKey)
158+
g.Expect(cct.clusterLock.TryLock(testClusterKey)).To(BeTrue())
159+
startHealthCheck := time.Now()
160+
cct.healthCheckCluster(ctx, &healthCheckInput{
161+
cluster: testClusterKey,
162+
cfg: env.Config,
163+
interval: testPollInterval,
164+
requestTimeout: testPollTimeout,
165+
unhealthyThreshold: testUnhealthyThreshold,
166+
path: "/",
167+
})
168+
timeElapsedForHealthCheck := time.Since(startHealthCheck)
169+
// If the duration is shorter than the timeout, we know that the healthcheck wasn't requeued properly.
170+
g.Expect(timeElapsedForHealthCheck).Should(BeNumerically(">=", time.Second))
171+
// The healthcheck should be aborted by the timout of the context
172+
g.Expect(ctx.Done()).Should(BeClosed())
173+
})
174+
149175
t.Run("with an invalid path", func(t *testing.T) {
150176
g := NewWithT(t)
151177
ns := setup(t, g)

0 commit comments

Comments
 (0)