|
7 | 7 | "fmt" |
8 | 8 | "strings" |
9 | 9 | "testing" |
| 10 | + "time" |
10 | 11 |
|
11 | 12 | prommodel "github.com/prometheus/client_model/go" |
12 | 13 | "github.com/prometheus/common/expfmt" |
@@ -165,20 +166,25 @@ func TestMetricGeneration(t *testing.T) { |
165 | 166 | // Send a test request to the interceptor |
166 | 167 | sendLoad(t, kc, data) |
167 | 168 |
|
168 | | - httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData() |
169 | | - KubectlApplyMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates) |
| 169 | + CreateManyHttpScaledObjecs(t, 10) |
| 170 | + time.Sleep(time.Second * 10) |
170 | 171 |
|
171 | 172 | // Fetch metrics and validate them |
172 | 173 | family := fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) |
173 | 174 | val, ok := family["keda_http_scaled_object_total"] |
174 | 175 | assert.True(t, ok, "keda_http_scaled_object_total is available") |
175 | | - |
176 | 176 | httpSacaledObjectCount := getMetricsValue(val) |
177 | | - assert.GreaterOrEqual(t, httpSacaledObjectCount, float64(1)) |
178 | | - assert.Equal(t, httpSacaledObjectCount, float64(2)) |
| 177 | + assert.GreaterOrEqual(t, httpSacaledObjectCount, float64(10)) |
| 178 | + |
| 179 | + DeleteManyHttpScaledObjecs(t, 10) |
| 180 | + time.Sleep(time.Second * 10) |
| 181 | + // Fetch metrics and validate them after deleting httpscaledobjects |
| 182 | + family = fetchAndParsePrometheusMetrics(t, fmt.Sprintf("curl --insecure %s", kedaOperatorPrometheusURL)) |
| 183 | + val, ok = family["keda_http_scaled_object_total"] |
| 184 | + httpSacaledObjectCountAfterCleanUp := getMetricsValue(val) |
| 185 | + assert.Equal(t, float64(1), httpSacaledObjectCountAfterCleanUp) |
179 | 186 |
|
180 | 187 | // cleanup |
181 | | - KubectlDeleteMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates) |
182 | 188 | DeleteKubernetesResources(t, testNamespace, data, templates) |
183 | 189 | } |
184 | 190 |
|
@@ -239,17 +245,35 @@ func getTemplateData() (templateData, []Template) { |
239 | 245 | } |
240 | 246 | } |
241 | 247 |
|
242 | | -func getTemplateHTTPScaledObjecData() (templateData, []Template) { |
| 248 | +func getTemplateHTTPScaledObjecData(httpScaledObjecID string) (templateData, []Template) { |
| 249 | + deploymentCustom := fmt.Sprintf("other-deployment-%s", httpScaledObjecID) |
| 250 | + httpScaledObjectCustom := fmt.Sprintf("other-http-scaled-object-name-%s", httpScaledObjecID) |
| 251 | + templateName := fmt.Sprintf("otherHttpScaledObjectName-%s", httpScaledObjecID) |
243 | 252 | return templateData{ |
244 | 253 | TestNamespace: testNamespace, |
245 | | - DeploymentName: "OtherDeployment", |
| 254 | + DeploymentName: deploymentCustom, |
246 | 255 | ServiceName: serviceName, |
247 | 256 | ClientName: clientName, |
248 | | - HTTPScaledObjectName: "OtherHttpScaledObjectName", |
| 257 | + HTTPScaledObjectName: httpScaledObjectCustom, |
249 | 258 | Host: host, |
250 | 259 | MinReplicas: minReplicaCount, |
251 | 260 | MaxReplicas: maxReplicaCount, |
252 | 261 | }, []Template{ |
253 | | - {Name: "OtherHttpScaledObjectName", Config: httpScaledObjectTemplate}, |
| 262 | + {Name: templateName, Config: httpScaledObjectTemplate}, |
254 | 263 | } |
255 | 264 | } |
| 265 | + |
| 266 | +func CreateManyHttpScaledObjecs(t *testing.T, objectsCount int) { |
| 267 | + for i := 0; i < objectsCount; i++ { |
| 268 | + httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData(fmt.Sprintf("%d", i)) |
| 269 | + KubectlApplyMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates) |
| 270 | + } |
| 271 | + |
| 272 | +} |
| 273 | +func DeleteManyHttpScaledObjecs(t *testing.T, objectsCount int) { |
| 274 | + for i := 0; i < objectsCount; i++ { |
| 275 | + httpScaledObjecData, httpScaledObjecDataTemplates := getTemplateHTTPScaledObjecData(fmt.Sprintf("%d", i)) |
| 276 | + KubectlDeleteMultipleWithTemplate(t, httpScaledObjecData, httpScaledObjecDataTemplates) |
| 277 | + } |
| 278 | + |
| 279 | +} |
0 commit comments