Testing that metrics with TTL > now are not removed

This test mostly serves as protection against regression

Signed-off-by: Muhammad Muaaz Saleem <muhammad.muaaz.saleem@zalando.de>
This commit is contained in:
Muhammad Muaaz Saleem
2018-11-20 11:00:13 +01:00
parent b1745c5eed
commit 553f8b5993

View File

@@ -208,7 +208,8 @@ func TestExternalMetricStorage(t *testing.T) {
func TestMetricsExpiration(t *testing.T) {
metricStore := NewMetricStore()
// Override global TTL to test expiration
// Temporarily Override global TTL to test expiration
tmpTTL := metricsTTL
metricsTTL = func() time.Time {
return time.Now().UTC().Add(time.Hour * -1)
}
@@ -238,6 +239,7 @@ func TestMetricsExpiration(t *testing.T) {
metricStore.Insert(customMetric)
metricStore.Insert(externalMetric)
metricStore.RemoveExpired()
customMetricInfos := metricStore.ListAllMetrics()
@@ -246,4 +248,43 @@ func TestMetricsExpiration(t *testing.T) {
externalMetricInfos := metricStore.ListAllExternalMetrics()
require.Len(t, externalMetricInfos, 0)
// set metricTTL to original
metricsTTL = tmpTTL
}
func TestMetricsNonExpiration(t *testing.T) {
metricStore := NewMetricStore()
customMetric := collector.CollectedMetric{
Type: v2beta1.MetricSourceType("Object"),
Custom: custom_metrics.MetricValue{
MetricName: "metric-per-unit",
Value: *resource.NewQuantity(0, ""),
DescribedObject: custom_metrics.ObjectReference{
Name: "metricObject",
Kind: "Node",
APIVersion: "core/v1",
},
},
}
externalMetric := collector.CollectedMetric{
Type: v2beta1.MetricSourceType("External"),
External: external_metrics.ExternalMetricValue{
MetricName: "metric-per-unit",
Value: *resource.NewQuantity(0, ""),
},
}
metricStore.Insert(customMetric)
metricStore.Insert(externalMetric)
metricStore.RemoveExpired()
customMetricInfos := metricStore.ListAllMetrics()
require.Len(t, customMetricInfos, 1)
externalMetricInfos := metricStore.ListAllExternalMetrics()
require.Len(t, externalMetricInfos, 1)
}