@@ -146,6 +146,32 @@ func TestClusterCacheHealthCheck(t *testing.T) {
146
146
}, 5 * time .Second , 1 * time .Second ).Should (BeTrue ())
147
147
})
148
148
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
+
149
175
t .Run ("with an invalid path" , func (t * testing.T ) {
150
176
g := NewWithT (t )
151
177
ns := setup (t , g )
0 commit comments