Skip to content

Commit

Permalink
chore: speed up ci and add timeout ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Jul 23, 2024
1 parent c570ed6 commit 76d87a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 43 deletions.
18 changes: 3 additions & 15 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
compatibility-test:
strategy:
matrix:
go: [ 1.15, "1.21" ]
go: [ 1.15, 1.22 ]
os: [ X64, ARM64 ]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -15,14 +15,8 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
# - uses: actions/cache@v2
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-
- name: Unit Test
run: go test -v -race -covermode=atomic -coverprofile=coverage.out ./...
run: go test -timeout=5m -v -race -covermode=atomic -coverprofile=coverage.out ./...
- name: Benchmark
run: go test -bench=. -benchmem -run=none ./...
windows-test:
Expand All @@ -32,13 +26,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20"
# - uses: actions/cache@v2
# with:
# path: ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-
go-version: 1.22
- name: Build Test
run: go vet -v ./...
style-test:
Expand Down
13 changes: 4 additions & 9 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestConnectionUntil(t *testing.T) {
rconn, wconn := &connection{}, &connection{}
rconn.init(&netFD{fd: r}, nil)
wconn.init(&netFD{fd: w}, nil)
loopSize := 100000
loopSize := 10000

msg := make([]byte, 1002)
msg[500], msg[1001] = '\n', '\n'
Expand Down Expand Up @@ -558,7 +558,6 @@ func TestConnDetach(t *testing.T) {
}

func TestParallelShortConnection(t *testing.T) {
t.Skip("TODO: it's not stable now, need fix CI")
address := getTestAddress()
ln, err := createTestListener("tcp", address)
MustNil(t, err)
Expand Down Expand Up @@ -599,11 +598,8 @@ func TestParallelShortConnection(t *testing.T) {
}
wg.Wait()

count := 100
for count > 0 && atomic.LoadInt64(&received) < int64(totalSize) {
t.Logf("received: %d, except: %d", atomic.LoadInt64(&received), totalSize)
time.Sleep(time.Millisecond * 100)
count--
for atomic.LoadInt64(&received) < int64(totalSize) {
runtime.Gosched()
}
Equal(t, atomic.LoadInt64(&received), int64(totalSize))
}
Expand Down Expand Up @@ -686,7 +682,7 @@ func TestConnectionServerClose(t *testing.T) {

return connection.Close()
}
conns := 100
conns := 32
// server: OnPrepare, OnConnect, OnRequest, CloseCallback
// client: OnRequest, CloseCallback
wg.Add(conns * 6)
Expand All @@ -703,7 +699,6 @@ func TestConnectionServerClose(t *testing.T) {
})
}()
}
//time.Sleep(time.Second)
wg.Wait()
}

Expand Down
34 changes: 18 additions & 16 deletions netpoll_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"os"
"runtime"
"sync"
Expand Down Expand Up @@ -270,40 +269,43 @@ func TestGracefulExit(t *testing.T) {
MustNil(t, err)

// exit with processing connections
trigger := make(chan struct{})
var eventLoop2 = newTestEventLoop(network, address,
func(ctx context.Context, connection Connection) error {
time.Sleep(10 * time.Second)
<-trigger
return nil
})
for i := 0; i < 10; i++ {
if i%2 == 0 {
var conn, err = DialConnection(network, address, time.Second)
MustNil(t, err)
_, err = conn.Write(make([]byte, 16))
MustNil(t, err)
}
// connect success
var conn, err = DialConnection(network, address, time.Second)
MustNil(t, err)
_, err = conn.Write(make([]byte, 16))
MustNil(t, err)
}
var ctx2, cancel2 = context.WithTimeout(context.Background(), 5*time.Second)
// shutdown timeout
var ctx2, cancel2 = context.WithTimeout(context.Background(), time.Millisecond*100)
defer cancel2()
err = eventLoop2.Shutdown(ctx2)
MustTrue(t, err != nil)
Equal(t, err.Error(), ctx2.Err().Error())
// shutdown success
close(trigger)
err = eventLoop2.Shutdown(ctx2)
MustTrue(t, err == nil)

// exit with some processing connections
// exit with read connections
size := 16
var eventLoop3 = newTestEventLoop(network, address,
func(ctx context.Context, connection Connection) error {
time.Sleep(time.Duration(rand.Intn(3)) * time.Second)
if l := connection.Reader().Len(); l > 0 {
var _, err = connection.Reader().Next(l)
MustNil(t, err)
}
_, err := connection.Reader().Next(size)
MustNil(t, err)
return nil
})
for i := 0; i < 10; i++ {
var conn, err = DialConnection(network, address, time.Second)
MustNil(t, err)
if i%2 == 0 {
_, err = conn.Write(make([]byte, 16))
_, err := conn.Write(make([]byte, size))
MustNil(t, err)
}
}
Expand Down
3 changes: 0 additions & 3 deletions poll_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ func TestPollManagerSetNumLoops(t *testing.T) {
wg.Add(1)
go func() {
poll := pm.Pick()
newGs := runtime.NumGoroutine()
t.Logf("old=%d, new=%d", oldGs, newGs)
Assert(t, poll != nil)
Assert(t, newGs-oldGs == 100)
Assert(t, len(pm.polls) == 100)
wg.Done()
<-finish // hold goroutines
Expand Down

0 comments on commit 76d87a9

Please sign in to comment.