Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Golang CI
on:
push:
branches:
- master
pull_request:

jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.18', '1.19', '1.20' ]
steps:
- uses: actions/checkout@v3

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build -v ./...

# TODO: uncomment this to enable golang lint
# - name: Lint
# uses: golangci/golangci-lint-action@v3
# with:
# version: v1.53

- name: Test
run: go test -json > TestResults-${{ matrix.go-version }}.json

- name: Upload Go test results
uses: actions/upload-artifact@v3
with:
name: Go-results-${{ matrix.go-version }}
path: TestResults-${{ matrix.go-version }}.json
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

42 changes: 22 additions & 20 deletions channel_rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ var (
MaximumCap = 100
network = "tcp"
address = "127.0.0.1:7777"
//factory = func() (interface{}, error) { return net.Dial(network, address) }
factory = func() (interface{}, error) {
return rpc.DialHTTP("tcp", address)
factory = func() (interface{}, error) {
return rpc.DialHTTP(network, address)
}
closeFac = func(v interface{}) error {
nc := v.(*rpc.Client)
Expand All @@ -30,7 +29,6 @@ func init() {
// used for factory function
go rpcServer()
time.Sleep(time.Millisecond * 300) // wait until tcp server has been settled

rand.Seed(time.Now().UTC().UnixNano())
}

Expand Down Expand Up @@ -67,8 +65,7 @@ func TestPool_Get(t *testing.T) {

// after one get, current capacity should be lowered by one.
if p.Len() != (InitialCap - 1) {
t.Errorf("Get error. Expecting %d, got %d",
(InitialCap - 1), p.Len())
t.Errorf("Get error. Expecting %d, got %d", InitialCap-1, p.Len())
}

// get them all
Expand All @@ -86,20 +83,19 @@ func TestPool_Get(t *testing.T) {
wg.Wait()

if p.Len() != 0 {
t.Errorf("Get error. Expecting %d, got %d",
(InitialCap - 1), p.Len())
}

_, err = p.Get()
if err != ErrMaxActiveConnReached {
t.Errorf("Get error: %s", err)
t.Errorf("Get error. Expecting %d, got %d", InitialCap-1, p.Len())
}

}

func TestPool_Put(t *testing.T) {
pconf := Config{InitialCap: InitialCap, MaxCap: MaximumCap, Factory: factory, Close: closeFac, IdleTimeout: time.Second * 20,
MaxIdle:MaxIdleCap}
pconf := Config{
InitialCap: InitialCap,
MaxCap: MaximumCap,
Factory: factory,
Close: closeFac,
IdleTimeout: time.Second * 20,
MaxIdle: MaxIdleCap,
}
p, err := NewChannelPool(&pconf)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -254,8 +250,14 @@ func TestPoolConcurrent2(t *testing.T) {
//}

func newChannelPool() (Pool, error) {
pconf := Config{InitialCap: InitialCap, MaxCap: MaximumCap, Factory: factory, Close: closeFac, IdleTimeout: time.Second * 20,
MaxIdle:MaxIdleCap}
pconf := Config{
InitialCap: InitialCap,
MaxCap: MaximumCap,
Factory: factory,
Close: closeFac,
IdleTimeout: time.Second * 20,
MaxIdle: MaxIdleCap,
}
return NewChannelPool(&pconf)
}

Expand All @@ -264,11 +266,11 @@ func rpcServer() {
rpc.Register(arith)
rpc.HandleHTTP()

l, e := net.Listen("tcp", address)
l, e := net.Listen(network, address)
if e != nil {
panic(e)
}
go http.Serve(l, nil)
http.Serve(l, nil)
}

type Args struct {
Expand Down