mirror of https://github.com/cbeuw/Cloak
Add tests
This commit is contained in:
parent
a1b719b15f
commit
34a4805c34
|
|
@ -153,7 +153,11 @@ func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) {
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sesh.recvDataFromRemote(obfsBuf[:n])
|
err := sesh.recvDataFromRemote(obfsBuf[:n])
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -166,7 +170,11 @@ func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) {
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sesh.recvDataFromRemote(obfsBuf[:n])
|
err := sesh.recvDataFromRemote(obfsBuf[:n])
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -179,7 +187,11 @@ func BenchmarkRecvDataFromRemote_Ordered(b *testing.B) {
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
sesh.recvDataFromRemote(obfsBuf[:n])
|
err := sesh.recvDataFromRemote(obfsBuf[:n])
|
||||||
|
if err != nil {
|
||||||
|
b.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
b.SetBytes(int64(n))
|
b.SetBytes(int64(n))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ package multiplex
|
||||||
import (
|
import (
|
||||||
"github.com/cbeuw/Cloak/internal/util"
|
"github.com/cbeuw/Cloak/internal/util"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSwitchboard_Send(t *testing.T) {
|
func TestSwitchboard_Send(t *testing.T) {
|
||||||
|
|
@ -148,3 +150,40 @@ func TestSwitchboard_TxCredit(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSwitchboard_CloseOnOneDisconn(t *testing.T) {
|
||||||
|
sesh := setupSesh(false)
|
||||||
|
|
||||||
|
l, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||||
|
addRemoteConn := func(close chan struct{}) {
|
||||||
|
conn, _ := net.Dial("tcp", l.Addr().String())
|
||||||
|
for {
|
||||||
|
conn.Write([]byte{0x00})
|
||||||
|
<-close
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close0 := make(chan struct{})
|
||||||
|
go addRemoteConn(close0)
|
||||||
|
conn0, _ := l.Accept()
|
||||||
|
sesh.AddConnection(conn0)
|
||||||
|
|
||||||
|
close1 := make(chan struct{})
|
||||||
|
go addRemoteConn(close1)
|
||||||
|
conn1, _ := l.Accept()
|
||||||
|
sesh.AddConnection(conn1)
|
||||||
|
|
||||||
|
close0 <- struct{}{}
|
||||||
|
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
if !sesh.IsClosed() {
|
||||||
|
t.Error("session not closed after one conn is disconnected")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if _, err := conn1.Write([]byte{0x00}); err == nil {
|
||||||
|
t.Error("the other conn is still connected")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue