mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 10:08:15 -05:00
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package mux_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"v2ray.com/core/common"
|
|
"v2ray.com/core/common/errors"
|
|
"v2ray.com/core/common/mux"
|
|
"v2ray.com/core/common/vio"
|
|
"v2ray.com/core/testing/mocks"
|
|
"v2ray.com/core/transport/pipe"
|
|
)
|
|
|
|
func TestIncrementalPickerFailure(t *testing.T) {
|
|
mockCtl := gomock.NewController(t)
|
|
defer mockCtl.Finish()
|
|
|
|
mockWorkerFactory := mocks.NewMuxClientWorkerFactory(mockCtl)
|
|
mockWorkerFactory.EXPECT().Create().Return(nil, errors.New("test"))
|
|
|
|
picker := mux.IncrementalWorkerPicker{
|
|
Factory: mockWorkerFactory,
|
|
}
|
|
|
|
_, err := picker.PickAvailable()
|
|
if err == nil {
|
|
t.Error("expected error, but nil")
|
|
}
|
|
}
|
|
|
|
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")
|
|
}
|
|
}
|