2014-12-29 13:43:56 +00:00
|
|
|
package peer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2015-09-30 23:24:00 +00:00
|
|
|
peer "github.com/ipfs/go-libp2p/p2p/peer"
|
2015-11-16 03:59:59 +00:00
|
|
|
testutil "github.com/ipfs/go-libp2p/testutil"
|
2014-12-29 13:43:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLatencyEWMAFun(t *testing.T) {
|
|
|
|
t.Skip("run it for fun")
|
|
|
|
|
|
|
|
m := peer.NewMetrics()
|
|
|
|
id, err := testutil.RandPeerID()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mu := 100.0
|
|
|
|
sig := 10.0
|
|
|
|
next := func() time.Duration {
|
|
|
|
mu = (rand.NormFloat64() * sig) + mu
|
|
|
|
return time.Duration(mu)
|
|
|
|
}
|
|
|
|
|
|
|
|
print := func() {
|
|
|
|
fmt.Printf("%3.f %3.f --> %d\n", sig, mu, m.LatencyEWMA(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-time.After(200 * time.Millisecond):
|
|
|
|
m.RecordLatency(id, next())
|
|
|
|
print()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|