Test that expired PeerMetrics gets deleted
This commit is contained in:
parent
cf189799f2
commit
76857112b2
|
@ -19,7 +19,7 @@ import (
|
||||||
var AlertChannelCap = 256
|
var AlertChannelCap = 256
|
||||||
|
|
||||||
// MaxAlertThreshold specifies how many alerts will occur per a peer is
|
// MaxAlertThreshold specifies how many alerts will occur per a peer is
|
||||||
// removed the list of monitored peers.
|
// removed from the list of monitored peers.
|
||||||
var MaxAlertThreshold = 1
|
var MaxAlertThreshold = 1
|
||||||
|
|
||||||
// ErrAlertChannelFull is returned if the alert channel is full.
|
// ErrAlertChannelFull is returned if the alert channel is full.
|
||||||
|
@ -191,7 +191,7 @@ func (mc *Checker) failed(metric string, pid peer.ID) (float64, []float64, float
|
||||||
return 0.0, nil, 0.0, true
|
return 0.0, nil, 0.0, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// A peer is never failed if the latest metric from is has
|
// A peer is never failed if the latest metric from it has
|
||||||
// not expired or we do not have enough number of metrics
|
// not expired or we do not have enough number of metrics
|
||||||
// for accrual detection
|
// for accrual detection
|
||||||
if !latest.Expired() {
|
if !latest.Expired() {
|
||||||
|
|
|
@ -312,3 +312,26 @@ func TestPeerMonitorAlerts(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMetricsGetsDeleted(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
pm, _, shutdown := testPeerMonitor(t)
|
||||||
|
defer shutdown()
|
||||||
|
mf := newMetricFactory()
|
||||||
|
|
||||||
|
pm.LogMetric(ctx, mf.newMetric("test", test.PeerID1))
|
||||||
|
metrics := pm.metrics.PeerMetrics(test.PeerID1)
|
||||||
|
if len(metrics) == 0 {
|
||||||
|
t.Error("expected metrics")
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: expiry time + checkInterval is 7 sec
|
||||||
|
// Why does it need 9 or more?
|
||||||
|
time.Sleep(9 * time.Second)
|
||||||
|
|
||||||
|
metrics = pm.metrics.PeerMetrics(test.PeerID1)
|
||||||
|
if len(metrics) > 0 {
|
||||||
|
t.Error("expected no metrics")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user