Skip to content

Commit

Permalink
test: make histogram tests less flaky
Browse files Browse the repository at this point in the history
The test only produces one sample sometimes, which is fine. We now
simply assert if there is at least one sample.
  • Loading branch information
ctrox committed Apr 28, 2024
1 parent f321b69 commit f105cce
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)),
},
}

Expand All @@ -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")
}
})
Expand Down

0 comments on commit f105cce

Please sign in to comment.