Skip to content

Commit

Permalink
fix tests and ci
Browse files Browse the repository at this point in the history
  • Loading branch information
p4gefau1t committed Jun 10, 2020
1 parent e81826c commit a0318cb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dev-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Test
run: go test ./...
- name: Build
run: mkdir dist && go build -tags "full" -o dist
- name: Upload Binary
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/docker-latest-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ on:
- 'docs'
tags:
- 'v*.*.*'
pull_request:
branches:
- 'master'
paths-ignore:
- '**.md'
- 'docs'
name: docker-build
jobs:
build:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/docker-nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ on:
push:
branches:
- 'dev'
pull_request:
branches:
- 'dev'
name: docker-dev-build
jobs:
build:
Expand Down
8 changes: 8 additions & 0 deletions test/util/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net"
"net/http"
"sync"
"time"
)

Expand Down Expand Up @@ -43,13 +44,15 @@ func runHelloHTTPServer() {
}
go server.ListenAndServe()
fmt.Println("http test server listening on", HTTPAddr)
wg.Done()
}

var EchoAddr string

func runTCPEchoServer() {
listener, err := net.Listen("tcp", EchoAddr)
common.Must(err)
wg.Done()
go func() {
for {
conn, err := listener.Accept()
Expand Down Expand Up @@ -77,6 +80,7 @@ func runTCPEchoServer() {
func runUDPEchoServer() {
conn, err := net.ListenPacket("udp", EchoAddr)
common.Must(err)
wg.Done()
go func() {
for {
buf := make([]byte, 1024*8)
Expand All @@ -96,9 +100,13 @@ func GeneratePayload(length int) []byte {
return buf
}

var wg = sync.WaitGroup{}

func init() {
wg.Add(3)
runHelloHTTPServer()
EchoAddr = GetTestAddr()
runTCPEchoServer()
runUDPEchoServer()
wg.Wait()
}
9 changes: 8 additions & 1 deletion tunnel/mux/mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ import (
)

func TestMux(t *testing.T) {
cfg := newDefaultConfig().(*Config)
cfg := &Config{
Mux: MuxConfig{
Enabled: true,
Concurrency: 8,
Timeout: 10,
},
}

data, err := yaml.Marshal(cfg)
common.Must(err)
fmt.Println(string(data))
Expand Down
12 changes: 7 additions & 5 deletions tunnel/socks/socks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package socks
import (
"context"
"fmt"
"net"
"sync"
"testing"

"github.com/p4gefau1t/trojan-go/common"
"github.com/p4gefau1t/trojan-go/config"
"github.com/p4gefau1t/trojan-go/test/util"
"github.com/p4gefau1t/trojan-go/tunnel"
"golang.org/x/net/proxy"
"net"
"sync"
"testing"
"time"
)

func TestSocks(t *testing.T) {
Expand All @@ -29,14 +29,16 @@ func TestSocks(t *testing.T) {
wg := sync.WaitGroup{}
wg.Add(2)

time.Sleep(time.Second * 2)
go func() {
conn2, err = s.AcceptConn(nil)
common.Must(err)
wg.Done()
}()

time.Sleep(time.Second * 1)
go func() {
conn1, err = socksClient.Dial("tcp", "www.baidu.com:80")
conn1, err = socksClient.Dial("tcp", util.EchoAddr)
common.Must(err)
wg.Done()
}()
Expand Down
1 change: 1 addition & 0 deletions tunnel/websocket/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func TestWebsocket(t *testing.T) {
cfg := &Config{
Websocket: WebsocketConfig{
Enabled: true,
Hostname: "localhost",
Path: "/ws",
},
Expand Down

0 comments on commit a0318cb

Please sign in to comment.