1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00
v2fly/common/mux/client_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2018-10-24 16:37:11 -04:00
package mux_test
import (
2018-10-25 03:32:03 -04:00
"context"
2018-10-24 16:37:11 -04:00
"testing"
2018-10-25 03:32:03 -04:00
"time"
2018-10-24 16:37:11 -04:00
2018-10-25 03:32:03 -04:00
"github.com/golang/mock/gomock"
"v2ray.com/core/common"
2018-10-24 16:37:11 -04:00
"v2ray.com/core/common/errors"
"v2ray.com/core/common/mux"
2018-10-25 03:32:03 -04:00
"v2ray.com/core/common/vio"
"v2ray.com/core/testing/mocks"
"v2ray.com/core/transport/pipe"
2018-10-24 16:37:11 -04:00
)
func TestIncrementalPickerFailure(t *testing.T) {
2018-10-25 03:32:03 -04:00
mockCtl := gomock.NewController(t)
defer mockCtl.Finish()
mockWorkerFactory := mocks.NewMuxClientWorkerFactory(mockCtl)
mockWorkerFactory.EXPECT().Create().Return(nil, errors.New("test"))
2018-10-24 16:37:11 -04:00
picker := mux.IncrementalWorkerPicker{
2018-10-25 03:32:03 -04:00
Factory: mockWorkerFactory,
2018-10-24 16:37:11 -04:00
}
_, err := picker.PickAvailable()
if err == nil {
t.Error("expected error, but nil")
}
}
2018-10-25 03:32:03 -04:00
func TestClientWorkerEOF(t *testing.T) {
reader, writer := pipe.New(pipe.WithoutSizeLimit())
common.Must(writer.Close())
worker, err := mux.NewClientWorker(vio.Link{Reader: reader, Writer: writer}, mux.ClientStrategy{})
common.Must(err)
time.Sleep(time.Millisecond * 500)
f := worker.Dispatch(context.Background(), nil)
if f {
t.Error("expected failed dispatching, but actually not")
}
}