Fix time-dependant tests

pull/132/head
Andy Wang 4 years ago
parent 9887649b88
commit f00ef43613

@ -190,6 +190,8 @@ func establishSession(lcc client.LocalConnConfig, rcc client.RemoteConnConfig, a
var proxyToCkClientD common.Dialer var proxyToCkClientD common.Dialer
if ai.Unordered { if ai.Unordered {
// We can only "dial" a single UDP connection as we can't send packets from different context
// to a single UDP listener
addrCh := make(chan *net.UDPAddr, 1) addrCh := make(chan *net.UDPAddr, 1)
mDialer := &mockUDPDialer{ mDialer := &mockUDPDialer{
addrCh: addrCh, addrCh: addrCh,
@ -251,7 +253,7 @@ func runEchoTest(t *testing.T, conns []net.Conn, maxMsgLen int) {
func TestUDP(t *testing.T) { func TestUDP(t *testing.T) {
var tmpDB, _ = ioutil.TempFile("", "ck_user_info") var tmpDB, _ = ioutil.TempFile("", "ck_user_info")
defer os.Remove(tmpDB.Name()) defer os.Remove(tmpDB.Name())
log.SetLevel(log.TraceLevel) log.SetLevel(log.ErrorLevel)
worldState := common.WorldOfTime(time.Unix(10, 0)) worldState := common.WorldOfTime(time.Unix(10, 0))
lcc, rcc, ai := generateClientConfigs(udpClientConfigs["basic"], worldState) lcc, rcc, ai := generateClientConfigs(udpClientConfigs["basic"], worldState)
@ -481,16 +483,19 @@ func TestClosingStreamsFromProxy(t *testing.T) {
clientConn, _ := proxyToCkClientD.Dial("", "") clientConn, _ := proxyToCkClientD.Dial("", "")
go func() { go func() {
clientConn.Write(testData) clientConn.Write(testData)
// TODO: this is time dependent. It could be due to the time it took for this // it takes time for this written data to be copied asynchronously
// connutil.StreamPipe's Close to be reflected on the copy function, instead of inherent bad sync // into ck-server's domain. If the pipe is closed before that, read
// in multiplexer // by ck-client in RoutTCP will fail as we have closed it.
time.Sleep(10 * time.Millisecond) time.Sleep(delayBeforeTestingConnClose)
clientConn.Close() clientConn.Close()
}() }()
readBuf := make([]byte, len(testData)) readBuf := make([]byte, len(testData))
serverConn, _ := proxyFromCkServerL.Accept() serverConn, err := proxyFromCkServerL.Accept()
_, err := io.ReadFull(serverConn, readBuf) if err != nil {
t.Errorf("failed to accept a connection delievering data sent before closing: %v", err)
}
_, err = io.ReadFull(serverConn, readBuf)
if err != nil { if err != nil {
t.Errorf("failed to read data sent before closing: %v", err) t.Errorf("failed to read data sent before closing: %v", err)
} }

Loading…
Cancel
Save