2018-05-08 09:38:12 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ipfs/ipfs-cluster/api"
|
|
|
|
"github.com/ipfs/ipfs-cluster/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreLatest(t *testing.T) {
|
|
|
|
store := NewStore()
|
|
|
|
|
2019-02-27 17:04:35 +00:00
|
|
|
metr := &api.Metric{
|
2018-05-08 09:38:12 +00:00
|
|
|
Name: "test",
|
2019-02-27 20:19:10 +00:00
|
|
|
Peer: test.PeerID1,
|
2018-05-08 09:38:12 +00:00
|
|
|
Value: "1",
|
|
|
|
Valid: true,
|
|
|
|
}
|
|
|
|
metr.SetTTL(200 * time.Millisecond)
|
|
|
|
store.Add(metr)
|
|
|
|
|
2019-02-20 14:24:25 +00:00
|
|
|
latest := store.LatestValid("test")
|
2018-05-08 09:38:12 +00:00
|
|
|
if len(latest) != 1 {
|
|
|
|
t.Error("expected 1 metric")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(220 * time.Millisecond)
|
|
|
|
|
2019-02-20 14:24:25 +00:00
|
|
|
latest = store.LatestValid("test")
|
2018-05-08 09:38:12 +00:00
|
|
|
if len(latest) != 0 {
|
|
|
|
t.Error("expected no metrics")
|
|
|
|
}
|
|
|
|
}
|