mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 15:36:41 -05:00
fix test break
This commit is contained in:
parent
5d23604713
commit
ef1d9d24cd
@ -1,7 +1,6 @@
|
|||||||
package mux_test
|
package mux_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -9,7 +8,7 @@ import (
|
|||||||
"v2ray.com/core/common/buf"
|
"v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/common/net"
|
"v2ray.com/core/common/net"
|
||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
"v2ray.com/core/transport/ray"
|
"v2ray.com/core/transport/pipe"
|
||||||
. "v2ray.com/ext/assert"
|
. "v2ray.com/ext/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,16 +30,16 @@ func readAll(reader buf.Reader) (buf.MultiBuffer, error) {
|
|||||||
func TestReaderWriter(t *testing.T) {
|
func TestReaderWriter(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
stream := ray.NewStream(context.Background())
|
pReader, pWriter := pipe.New()
|
||||||
|
|
||||||
dest := net.TCPDestination(net.DomainAddress("v2ray.com"), 80)
|
dest := net.TCPDestination(net.DomainAddress("v2ray.com"), 80)
|
||||||
writer := NewWriter(1, dest, stream, protocol.TransferTypeStream)
|
writer := NewWriter(1, dest, pWriter, protocol.TransferTypeStream)
|
||||||
|
|
||||||
dest2 := net.TCPDestination(net.LocalHostIP, 443)
|
dest2 := net.TCPDestination(net.LocalHostIP, 443)
|
||||||
writer2 := NewWriter(2, dest2, stream, protocol.TransferTypeStream)
|
writer2 := NewWriter(2, dest2, pWriter, protocol.TransferTypeStream)
|
||||||
|
|
||||||
dest3 := net.TCPDestination(net.LocalHostIPv6, 18374)
|
dest3 := net.TCPDestination(net.LocalHostIPv6, 18374)
|
||||||
writer3 := NewWriter(3, dest3, stream, protocol.TransferTypeStream)
|
writer3 := NewWriter(3, dest3, pWriter, protocol.TransferTypeStream)
|
||||||
|
|
||||||
writePayload := func(writer *Writer, payload ...byte) error {
|
writePayload := func(writer *Writer, payload ...byte) error {
|
||||||
b := buf.New()
|
b := buf.New()
|
||||||
@ -60,7 +59,7 @@ func TestReaderWriter(t *testing.T) {
|
|||||||
assert(writePayload(writer2, 'y'), IsNil)
|
assert(writePayload(writer2, 'y'), IsNil)
|
||||||
writer2.Close()
|
writer2.Close()
|
||||||
|
|
||||||
bytesReader := buf.NewBufferedReader(stream)
|
bytesReader := buf.NewBufferedReader(pReader)
|
||||||
|
|
||||||
meta, err := ReadMetadata(bytesReader)
|
meta, err := ReadMetadata(bytesReader)
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
@ -133,7 +132,7 @@ func TestReaderWriter(t *testing.T) {
|
|||||||
assert(meta.SessionID, Equals, uint16(2))
|
assert(meta.SessionID, Equals, uint16(2))
|
||||||
assert(byte(meta.Option), Equals, byte(0))
|
assert(byte(meta.Option), Equals, byte(0))
|
||||||
|
|
||||||
stream.Close()
|
pWriter.Close()
|
||||||
|
|
||||||
meta, err = ReadMetadata(bytesReader)
|
meta, err = ReadMetadata(bytesReader)
|
||||||
assert(err, IsNotNil)
|
assert(err, IsNotNil)
|
||||||
|
@ -2,12 +2,11 @@ package buf_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "v2ray.com/core/common/buf"
|
. "v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/transport/ray"
|
"v2ray.com/core/transport/pipe"
|
||||||
. "v2ray.com/ext/assert"
|
. "v2ray.com/ext/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,24 +38,24 @@ func TestAdaptiveReader(t *testing.T) {
|
|||||||
func TestBytesReaderWriteTo(t *testing.T) {
|
func TestBytesReaderWriteTo(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
stream := ray.NewStream(context.Background())
|
pReader, pWriter := pipe.New()
|
||||||
reader := NewBufferedReader(stream)
|
reader := NewBufferedReader(pReader)
|
||||||
b1 := New()
|
b1 := New()
|
||||||
b1.AppendBytes('a', 'b', 'c')
|
b1.AppendBytes('a', 'b', 'c')
|
||||||
b2 := New()
|
b2 := New()
|
||||||
b2.AppendBytes('e', 'f', 'g')
|
b2.AppendBytes('e', 'f', 'g')
|
||||||
assert(stream.WriteMultiBuffer(NewMultiBufferValue(b1, b2)), IsNil)
|
assert(pWriter.WriteMultiBuffer(NewMultiBufferValue(b1, b2)), IsNil)
|
||||||
stream.Close()
|
pWriter.Close()
|
||||||
|
|
||||||
stream2 := ray.NewStream(context.Background())
|
pReader2, pWriter2 := pipe.New()
|
||||||
writer := NewBufferedWriter(stream2)
|
writer := NewBufferedWriter(pWriter2)
|
||||||
writer.SetBuffered(false)
|
writer.SetBuffered(false)
|
||||||
|
|
||||||
nBytes, err := io.Copy(writer, reader)
|
nBytes, err := io.Copy(writer, reader)
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
assert(nBytes, Equals, int64(6))
|
assert(nBytes, Equals, int64(6))
|
||||||
|
|
||||||
mb, err := stream2.ReadMultiBuffer()
|
mb, err := pReader2.ReadMultiBuffer()
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
assert(len(mb), Equals, 2)
|
assert(len(mb), Equals, 2)
|
||||||
assert(mb[0].String(), Equals, "abc")
|
assert(mb[0].String(), Equals, "abc")
|
||||||
@ -66,14 +65,14 @@ func TestBytesReaderWriteTo(t *testing.T) {
|
|||||||
func TestBytesReaderMultiBuffer(t *testing.T) {
|
func TestBytesReaderMultiBuffer(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
stream := ray.NewStream(context.Background())
|
pReader, pWriter := pipe.New()
|
||||||
reader := NewBufferedReader(stream)
|
reader := NewBufferedReader(pReader)
|
||||||
b1 := New()
|
b1 := New()
|
||||||
b1.AppendBytes('a', 'b', 'c')
|
b1.AppendBytes('a', 'b', 'c')
|
||||||
b2 := New()
|
b2 := New()
|
||||||
b2.AppendBytes('e', 'f', 'g')
|
b2.AppendBytes('e', 'f', 'g')
|
||||||
assert(stream.WriteMultiBuffer(NewMultiBufferValue(b1, b2)), IsNil)
|
assert(pWriter.WriteMultiBuffer(NewMultiBufferValue(b1, b2)), IsNil)
|
||||||
stream.Close()
|
pWriter.Close()
|
||||||
|
|
||||||
mbReader := NewReader(reader)
|
mbReader := NewReader(reader)
|
||||||
mb, err := mbReader.ReadMultiBuffer()
|
mb, err := mbReader.ReadMultiBuffer()
|
||||||
|
@ -4,14 +4,12 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"context"
|
|
||||||
"io"
|
"io"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"v2ray.com/core/common"
|
"v2ray.com/core/common"
|
||||||
. "v2ray.com/core/common/buf"
|
. "v2ray.com/core/common/buf"
|
||||||
"v2ray.com/core/transport/ray"
|
"v2ray.com/core/transport/pipe"
|
||||||
. "v2ray.com/ext/assert"
|
. "v2ray.com/ext/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -36,16 +34,16 @@ func TestWriter(t *testing.T) {
|
|||||||
func TestBytesWriterReadFrom(t *testing.T) {
|
func TestBytesWriterReadFrom(t *testing.T) {
|
||||||
assert := With(t)
|
assert := With(t)
|
||||||
|
|
||||||
cache := ray.NewStream(context.Background())
|
pReader, pWriter := pipe.New()
|
||||||
const size = 50000
|
const size = 50000
|
||||||
reader := bufio.NewReader(io.LimitReader(rand.Reader, size))
|
reader := bufio.NewReader(io.LimitReader(rand.Reader, size))
|
||||||
writer := NewBufferedWriter(cache)
|
writer := NewBufferedWriter(pWriter)
|
||||||
writer.SetBuffered(false)
|
writer.SetBuffered(false)
|
||||||
nBytes, err := reader.WriteTo(writer)
|
nBytes, err := reader.WriteTo(writer)
|
||||||
assert(nBytes, Equals, int64(size))
|
assert(nBytes, Equals, int64(size))
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
|
|
||||||
mb, err := cache.ReadMultiBuffer()
|
mb, err := pReader.ReadMultiBuffer()
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
assert(mb.Len(), Equals, int32(size))
|
assert(mb.Len(), Equals, int32(size))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user