1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-31 00:08:08 -04:00
v2fly/transport/internet/kcp/sending_test.go

110 lines
2.2 KiB
Go
Raw Normal View History

2016-06-26 17:51:17 -04:00
package kcp_test
import (
"testing"
2016-07-13 15:47:40 -04:00
"github.com/v2ray/v2ray-core/common/alloc"
2016-06-26 17:51:17 -04:00
"github.com/v2ray/v2ray-core/testing/assert"
. "github.com/v2ray/v2ray-core/transport/internet/kcp"
)
func TestSendingQueue(t *testing.T) {
assert := assert.On(t)
queue := NewSendingQueue(3)
2016-07-28 10:24:15 -04:00
seg0 := alloc.NewLocalBuffer(512)
seg1 := alloc.NewLocalBuffer(512)
seg2 := alloc.NewLocalBuffer(512)
seg3 := alloc.NewLocalBuffer(512)
2016-06-26 17:51:17 -04:00
assert.Bool(queue.IsEmpty()).IsTrue()
assert.Bool(queue.IsFull()).IsFalse()
queue.Push(seg0)
assert.Bool(queue.IsEmpty()).IsFalse()
queue.Push(seg1)
queue.Push(seg2)
assert.Bool(queue.IsFull()).IsTrue()
assert.Pointer(queue.Pop()).Equals(seg0)
queue.Push(seg3)
assert.Bool(queue.IsFull()).IsTrue()
assert.Pointer(queue.Pop()).Equals(seg1)
assert.Pointer(queue.Pop()).Equals(seg2)
assert.Pointer(queue.Pop()).Equals(seg3)
assert.Int(int(queue.Len())).Equals(0)
}
func TestSendingQueueClear(t *testing.T) {
assert := assert.On(t)
queue := NewSendingQueue(3)
2016-07-28 10:24:15 -04:00
seg0 := alloc.NewLocalBuffer(512)
seg1 := alloc.NewLocalBuffer(512)
seg2 := alloc.NewLocalBuffer(512)
seg3 := alloc.NewLocalBuffer(512)
2016-06-26 17:51:17 -04:00
queue.Push(seg0)
assert.Bool(queue.IsEmpty()).IsFalse()
queue.Clear()
assert.Bool(queue.IsEmpty()).IsTrue()
queue.Push(seg1)
queue.Push(seg2)
queue.Push(seg3)
queue.Clear()
assert.Bool(queue.IsEmpty()).IsTrue()
}
2016-07-01 05:57:13 -04:00
func TestSendingWindow(t *testing.T) {
assert := assert.On(t)
2016-07-04 11:01:32 -04:00
window := NewSendingWindow(5, nil, nil)
2016-07-01 05:57:13 -04:00
window.Push(&DataSegment{
Number: 0,
})
window.Push(&DataSegment{
Number: 1,
})
window.Push(&DataSegment{
Number: 2,
})
assert.Int(window.Len()).Equals(3)
window.Remove(1)
assert.Int(window.Len()).Equals(3)
assert.Uint32(window.First().Number).Equals(0)
window.Remove(0)
assert.Int(window.Len()).Equals(1)
assert.Uint32(window.First().Number).Equals(2)
window.Remove(0)
assert.Int(window.Len()).Equals(0)
window.Push(&DataSegment{
Number: 4,
})
assert.Int(window.Len()).Equals(1)
assert.Uint32(window.First().Number).Equals(4)
window.Push(&DataSegment{
Number: 5,
})
assert.Int(window.Len()).Equals(2)
window.Remove(1)
assert.Int(window.Len()).Equals(2)
window.Remove(0)
assert.Int(window.Len()).Equals(0)
2016-07-01 05:57:13 -04:00
}