1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 01:17:30 -05:00

Added Test for dial

This commit is contained in:
Shelikhoo 2018-04-05 16:17:17 +08:00
parent d08929a687
commit 4e609c9758
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -92,3 +92,41 @@ func TestListenA(t *testing.T) {
fin() fin()
listener.Down() listener.Down()
} }
func TestListenDial(t *testing.T) {
listener, err := domainsocket.ListenDS(context.Background(), "\x00/tmp/ts")
asrt := assert.With(t)
asrt(err, assert.IsNil)
asrt(listener, assert.IsNotNil)
errolu := listener.LowerUP()
asrt(errolu, assert.IsNil)
ctx, fin := context.WithCancel(context.Background())
chi := make(chan net.Conn, 2)
go func() {
for {
select {
case conn := <-chi:
test := make([]byte, 256)
nc, errc := conn.Read(test)
asrt(errc, assert.IsNil)
conn.Write(test[:nc])
time.Sleep(time.Second)
conn.Close()
case <-ctx.Done():
return
}
}
}()
listener.UP(chi, false)
con, erro := domainsocket.DialDS(context.Background(), "\x00/tmp/ts")
asrt(erro, assert.IsNil)
b := []byte("ABC")
c := []byte("XXX")
_, erron := con.Write(b)
asrt(erron, assert.IsNil)
con.Read(c)
con.Close()
asrt(b[0]-c[0] == 0, assert.IsTrue)
fin()
listener.Down()
}