Skip to content

Commit

Permalink
fix test timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Jul 14, 2020
1 parent 2147c56 commit a0d783b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ require (
github.com/txthinking/x v0.0.0-20200330144832-5ad2416896a9 // indirect
github.com/xtaci/smux v1.5.14
go.starlark.net v0.0.0-20200619143648-50ca820fafb9 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20200625001655-4c5254603344
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand All @@ -101,8 +103,8 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200707034311-ab3426394381 h1:VXak5I6aEWmAXeQjA+QSZzlgNrpq9mjcfDemuexIKsU=
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
41 changes: 22 additions & 19 deletions redirector/redirector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ package redirector

import (
"context"
"fmt"
"net"
"net/http"
"strings"
"testing"
"time"

"github.com/p4gefau1t/trojan-go/common"
"github.com/p4gefau1t/trojan-go/test/util"
)

func TestRedirector(t *testing.T) {
Expand Down Expand Up @@ -39,25 +44,23 @@ func TestRedirector(t *testing.T) {
common.Must(err)
conn2, err := l.Accept()
common.Must(err)
// TODO fix timeout
/*
redirAddr, err := net.ResolveTCPAddr("tcp", util.HTTPAddr)
common.Must(err)
redir.Redirect(&Redirection{
Dial: nil,
RedirectTo: redirAddr,
InboundConn: conn2,
})
req, err := http.NewRequest("GET", "http://localhost/", nil)
common.Must(err)
req.Write(conn1)
buf := make([]byte, 1024)
conn1.Read(buf)
fmt.Println(string(buf))
if !strings.HasPrefix(string(buf), "HTTP/1.1 200 OK") {
t.Fail()
}
*/
redirAddr, err := net.ResolveTCPAddr("tcp", util.HTTPAddr)
common.Must(err)
redir.Redirect(&Redirection{
Dial: nil,
RedirectTo: redirAddr,
InboundConn: conn2,
})
time.Sleep(time.Second)
req, err := http.NewRequest("GET", "http://localhost/", nil)
common.Must(err)
req.Write(conn1)
buf := make([]byte, 1024)
conn1.Read(buf)
fmt.Println(string(buf))
if !strings.HasPrefix(string(buf), "HTTP/1.1 200 OK") {
t.Fail()
}
cancel()
conn1.Close()
conn2.Close()
Expand Down
2 changes: 1 addition & 1 deletion test/util/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func runHelloHTTPServer() {
Handler: mux,
}
go server.ListenAndServe()
time.Sleep(time.Second * 3) // wait for http server
time.Sleep(time.Second * 1) // wait for http server
fmt.Println("http test server listening on", HTTPAddr)
wg.Done()
}
Expand Down
3 changes: 3 additions & 0 deletions tunnel/websocket/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"sync"
"testing"
"time"

"github.com/p4gefau1t/trojan-go/common"
"github.com/p4gefau1t/trojan-go/config"
Expand Down Expand Up @@ -51,6 +52,7 @@ func TestWebsocket(t *testing.T) {
common.Must(err)
wg.Done()
}()
time.Sleep(time.Second)
conn1, err := c.DialConn(nil, nil)
common.Must(err)
wg.Wait()
Expand Down Expand Up @@ -101,6 +103,7 @@ func TestRedirect(t *testing.T) {
t.Fail()
}
}()
time.Sleep(time.Second)
conn, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", port))
common.Must(err)
url := "wss://localhost/wrong-path"
Expand Down

0 comments on commit a0d783b

Please sign in to comment.