Ensure ConnStats spew nicely
This commit is contained in:
parent
224522545b
commit
5cb73d6a37
|
@ -1,6 +1,7 @@
|
||||||
package torrent
|
package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -48,6 +49,8 @@ type Count struct {
|
||||||
n int64
|
n int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var _ fmt.Stringer = (*Count)(nil)
|
||||||
|
|
||||||
func (me *Count) Add(n int64) {
|
func (me *Count) Add(n int64) {
|
||||||
atomic.AddInt64(&me.n, n)
|
atomic.AddInt64(&me.n, n)
|
||||||
}
|
}
|
||||||
|
@ -56,6 +59,10 @@ func (me *Count) Int64() int64 {
|
||||||
return atomic.LoadInt64(&me.n)
|
return atomic.LoadInt64(&me.n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *Count) String() string {
|
||||||
|
return fmt.Sprintf("%v", me.Int64())
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *ConnStats) wroteMsg(msg *pp.Message) {
|
func (cs *ConnStats) wroteMsg(msg *pp.Message) {
|
||||||
// TODO: Track messages and not just chunks.
|
// TODO: Track messages and not just chunks.
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
|
|
10
misc_test.go
10
misc_test.go
|
@ -1,10 +1,13 @@
|
||||||
package torrent
|
package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/anacrolix/missinggo/bitmap"
|
"github.com/anacrolix/missinggo/bitmap"
|
||||||
"github.com/anacrolix/missinggo/iter"
|
"github.com/anacrolix/missinggo/iter"
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,3 +32,10 @@ func TestIterBitmapsDistinct(t *testing.T) {
|
||||||
assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second)))
|
assert.Equal(t, []interface{}{0, 3, 2}, iter.ToSlice(iterBitmapsDistinct(&skipCopy, first, second)))
|
||||||
assert.Equal(t, []int{1}, skip.ToSortedSlice())
|
assert.Equal(t, []int{1}, skip.ToSortedSlice())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSpewConnStats(t *testing.T) {
|
||||||
|
s := spew.Sdump(ConnStats{})
|
||||||
|
t.Logf("\n%s\n", s)
|
||||||
|
lines := strings.Count(s, "\n")
|
||||||
|
assert.EqualValues(t, 2+reflect.ValueOf(ConnStats{}).NumField(), lines)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue