1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-28 10:15:23 +00:00
v2fly/app/dispatcher/stats_test.go

45 lines
833 B
Go
Raw Normal View History

2018-11-03 12:05:23 +00:00
package dispatcher_test
2018-10-15 07:03:40 +00:00
import (
"testing"
. "github.com/v2fly/v2ray-core/v5/app/dispatcher"
"github.com/v2fly/v2ray-core/v5/common"
"github.com/v2fly/v2ray-core/v5/common/buf"
2018-10-15 07:03:40 +00:00
)
type TestCounter int64
func (c *TestCounter) Value() int64 {
return int64(*c)
}
func (c *TestCounter) Add(v int64) int64 {
x := int64(*c) + v
*c = TestCounter(x)
return x
}
func (c *TestCounter) Set(v int64) int64 {
*c = TestCounter(v)
return v
}
func TestStatsWriter(t *testing.T) {
var c TestCounter
writer := &SizeStatWriter{
Counter: &c,
Writer: buf.Discard,
}
2018-11-18 18:36:36 +00:00
mb := buf.MergeBytes(nil, []byte("abcd"))
2018-10-15 07:03:40 +00:00
common.Must(writer.WriteMultiBuffer(mb))
2018-11-18 18:36:36 +00:00
mb = buf.MergeBytes(nil, []byte("efg"))
2018-10-15 07:03:40 +00:00
common.Must(writer.WriteMultiBuffer(mb))
if c.Value() != 7 {
t.Fatal("unexpected counter value. want 7, but got ", c.Value())
}
}