mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 01:08:33 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
44
app/dispatcher/stats_test.go
Normal file
44
app/dispatcher/stats_test.go
Normal file
|
@ -0,0 +1,44 @@
|
|||
package dispatcher_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/xtls/xray-core/v1/app/dispatcher"
|
||||
"github.com/xtls/xray-core/v1/common"
|
||||
"github.com/xtls/xray-core/v1/common/buf"
|
||||
)
|
||||
|
||||
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,
|
||||
}
|
||||
|
||||
mb := buf.MergeBytes(nil, []byte("abcd"))
|
||||
common.Must(writer.WriteMultiBuffer(mb))
|
||||
|
||||
mb = buf.MergeBytes(nil, []byte("efg"))
|
||||
common.Must(writer.WriteMultiBuffer(mb))
|
||||
|
||||
if c.Value() != 7 {
|
||||
t.Fatal("unexpected counter value. want 7, but got ", c.Value())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue