From f105ccece7a67580c336ed8ecd6874b113ffced4 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Sun, 28 Apr 2024 14:44:38 +0200 Subject: [PATCH] test: make histogram tests less flaky The test only produces one sample sometimes, which is fine. We now simply assert if there is at least one sample. --- e2e/e2e_test.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 196ce6f..ddcb1e1 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -202,10 +202,10 @@ func TestE2E(t *testing.T) { mfs := getNodeMetrics(t, client, cfg) tests := map[string]struct { - metric string - pod *corev1.Pod - gaugeValue *float64 - histogramSampleCount *uint64 + metric string + pod *corev1.Pod + gaugeValue *float64 + minHistogramSampleCount *uint64 }{ "running": { metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricRunning), @@ -222,20 +222,18 @@ func TestE2E(t *testing.T) { pod: checkpointedPod, }, "checkpoint duration": { - metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricCheckPointDuration), - pod: checkpointedPod, - // we expect two checkpoints as the first one happens due to the startupProbe - histogramSampleCount: ptr.To(uint64(2)), + metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricCheckPointDuration), + pod: checkpointedPod, + minHistogramSampleCount: ptr.To(uint64(1)), }, "last restore time": { metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricLastRestoreTime), pod: restoredPod, }, "restore duration": { - metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricRestoreDuration), - pod: restoredPod, - // we expect two restores as the first one happens due to the startupProbe - histogramSampleCount: ptr.To(uint64(2)), + metric: prometheus.BuildFQName(zeropod.MetricsNamespace, "", zeropod.MetricRestoreDuration), + pod: restoredPod, + minHistogramSampleCount: ptr.To(uint64(1)), }, } @@ -260,8 +258,8 @@ func TestE2E(t *testing.T) { "gauge value does not match expectation") } - if tc.histogramSampleCount != nil { - assert.Equal(t, *tc.histogramSampleCount, *metric.Histogram.SampleCount, + if tc.minHistogramSampleCount != nil { + assert.GreaterOrEqual(t, *metric.Histogram.SampleCount, *tc.minHistogramSampleCount, "histogram sample count does not match expectation") } })