2016-12-22 11:28:06 -05:00
|
|
|
package ray_test
|
|
|
|
|
|
|
|
import (
|
2017-04-13 16:17:58 -04:00
|
|
|
"context"
|
2016-12-22 11:28:06 -05:00
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"v2ray.com/core/common/buf"
|
|
|
|
. "v2ray.com/core/transport/ray"
|
2017-10-26 15:44:22 -04:00
|
|
|
. "v2ray.com/ext/assert"
|
2016-12-22 11:28:06 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStreamIO(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
2017-01-26 14:46:44 -05:00
|
|
|
stream := NewStream(context.Background())
|
2016-12-26 18:44:11 -05:00
|
|
|
b1 := buf.New()
|
|
|
|
b1.AppendBytes('a')
|
2017-11-09 16:33:15 -05:00
|
|
|
assert(stream.WriteMultiBuffer(buf.NewMultiBufferValue(b1)), IsNil)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
2017-11-09 16:33:15 -05:00
|
|
|
_, err := stream.ReadMultiBuffer()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
|
|
|
stream.Close()
|
2017-11-09 16:33:15 -05:00
|
|
|
_, err = stream.ReadMultiBuffer()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, Equals, io.EOF)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
2016-12-26 18:44:11 -05:00
|
|
|
b2 := buf.New()
|
|
|
|
b2.AppendBytes('b')
|
2017-11-09 16:33:15 -05:00
|
|
|
err = stream.WriteMultiBuffer(buf.NewMultiBufferValue(b2))
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, Equals, io.ErrClosedPipe)
|
2016-12-22 11:28:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStreamClose(t *testing.T) {
|
2017-10-24 10:15:35 -04:00
|
|
|
assert := With(t)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
2017-01-26 14:46:44 -05:00
|
|
|
stream := NewStream(context.Background())
|
2016-12-26 18:44:11 -05:00
|
|
|
b1 := buf.New()
|
|
|
|
b1.AppendBytes('a')
|
2017-11-09 16:33:15 -05:00
|
|
|
assert(stream.WriteMultiBuffer(buf.NewMultiBufferValue(b1)), IsNil)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
|
|
|
stream.Close()
|
|
|
|
|
2017-11-09 16:33:15 -05:00
|
|
|
_, err := stream.ReadMultiBuffer()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, IsNil)
|
2016-12-22 11:28:06 -05:00
|
|
|
|
2017-11-09 16:33:15 -05:00
|
|
|
_, err = stream.ReadMultiBuffer()
|
2017-10-24 10:15:35 -04:00
|
|
|
assert(err, Equals, io.EOF)
|
2016-12-22 11:28:06 -05:00
|
|
|
}
|