From d7f9a810cae93160c53bd23cc4136ee56a857c15 Mon Sep 17 00:00:00 2001 From: Fionera Date: Tue, 7 Nov 2023 02:50:04 +0100 Subject: [PATCH] tests and actions --- .github/workflows/go.yml | 65 ++++++++++++++++++++++++++++++++++++++++ go.mod | 8 +---- go.sum | 11 ++----- identity_test.go | 24 ++++++++------- internal/tools/go.mod | 13 ++++++++ internal/tools/go.sum | 14 +++++++++ internal/tools/tools.go | 7 +++++ validator_pow_test.go | 32 +++++++++++--------- 8 files changed, 134 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/go.yml create mode 100644 internal/tools/go.mod create mode 100644 internal/tools/go.sum create mode 100644 internal/tools/tools.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..cd0b420 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,65 @@ +name: Go + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - uses: dominikh/staticcheck-action@v1.3.0 + with: + install-go: false + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Build + run: go build -v ./... + + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: Test + run: go test -v ./... + + e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + + - name: setup environment + run: | + sudo apt-get install -y software-properties-common + sudo add-apt-repository -y ppa:vbernat/haproxy-2.8 + sudo apt-get update + sudo apt-get install -y haproxy + haproxy -vv + + - name: Test E2E + run: go test -v ./... --tags=e2e \ No newline at end of file diff --git a/go.mod b/go.mod index 61d2b15..8cd1df9 100644 --- a/go.mod +++ b/go.mod @@ -2,13 +2,7 @@ module github.com/fionera/berghain go 1.21 -replace github.com/dropmorepackets/haproxy-go => ../haproxy-go - require ( - github.com/dropmorepackets/haproxy-go v0.0.3 + github.com/dropmorepackets/haproxy-go v0.0.4 gopkg.in/yaml.v3 v3.0.1 ) - -require ( - github.com/adrianbrad/queue v1.2.1 // indirect -) diff --git a/go.sum b/go.sum index 148a09a..92abd30 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,5 @@ -github.com/adrianbrad/queue v1.2.1 h1:CEVsjFQyuR0s5Hty/HJGWBZHsJ3KMmii0kEgLeam/mk= -github.com/adrianbrad/queue v1.2.1/go.mod h1:wYiPC/3MPbyT45QHLrPR4zcqJWPePubM1oEP/xTwhUs= -github.com/klauspost/cpuid/v2 v2.2.3 h1:sxCkb+qR91z4vsqw4vGGZlDgPz3G7gjaLyK3V8y70BU= -github.com/klauspost/cpuid/v2 v2.2.3/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= -github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= -github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +github.com/dropmorepackets/haproxy-go v0.0.4 h1:bZQ8KHu00s/AyVNXW2kp9TKwpIWso2xTA3UfZmyxMGM= +github.com/dropmorepackets/haproxy-go v0.0.4/go.mod h1:OGwftKhVqRvI1QtonOPCvPHKgDQLLaZpT2aF25ReQ2Q= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/identity_test.go b/identity_test.go index 3b2412e..be78c89 100644 --- a/identity_test.go +++ b/identity_test.go @@ -23,13 +23,15 @@ func BenchmarkRequestIdentifier_ToCookie(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { - cb := AcquireCookieBuffer() - if err := ri.ToCookie(bh, cb); err != nil { - b.Fatal(err) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + cb := AcquireCookieBuffer() + if err := ri.ToCookie(bh, cb); err != nil { + b.Fatal(err) + } + ReleaseCookieBuffer(cb) } - ReleaseCookieBuffer(cb) - } + }) } func BenchmarkRequestIdentifier_IsValidCookie(b *testing.B) { @@ -55,9 +57,11 @@ func BenchmarkRequestIdentifier_IsValidCookie(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { - if err := bh.IsValidCookie(ri, cb.ReadBytes()); err != nil { - b.Fatal(err) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + if err := bh.IsValidCookie(ri, cb.ReadBytes()); err != nil { + b.Fatal(err) + } } - } + }) } diff --git a/internal/tools/go.mod b/internal/tools/go.mod new file mode 100644 index 0000000..a3d460a --- /dev/null +++ b/internal/tools/go.mod @@ -0,0 +1,13 @@ +module github.com/dropmorepackets/berghain/internal/tools + +go 1.21 + +require honnef.co/go/tools v0.4.6 + +require ( + github.com/BurntSushi/toml v1.2.1 // indirect + golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect +) diff --git a/internal/tools/go.sum b/internal/tools/go.sum new file mode 100644 index 0000000..3e98c9f --- /dev/null +++ b/internal/tools/go.sum @@ -0,0 +1,14 @@ +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +honnef.co/go/tools v0.4.6 h1:oFEHCKeID7to/3autwsWfnuv69j3NsfcXbvJKuIcep8= +honnef.co/go/tools v0.4.6/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= diff --git a/internal/tools/tools.go b/internal/tools/tools.go new file mode 100644 index 0000000..0f9cf9a --- /dev/null +++ b/internal/tools/tools.go @@ -0,0 +1,7 @@ +//go:build tools + +package tools + +import ( + _ "honnef.co/go/tools/cmd/staticcheck" +) diff --git a/validator_pow_test.go b/validator_pow_test.go index 8523ac7..65cfc08 100644 --- a/validator_pow_test.go +++ b/validator_pow_test.go @@ -117,14 +117,16 @@ func Benchmark_validatorPOW_GET(b *testing.B) { req.Method = http.MethodGet b.ResetTimer() - for i := 0; i < b.N; i++ { - resp := AcquireValidatorResponse() - if err := validatorPOW(bh, req, resp); err != nil { - b.Errorf("validator failed: %v", err) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + resp := AcquireValidatorResponse() + if err := validatorPOW(bh, req, resp); err != nil { + b.Errorf("validator failed: %v", err) + } + + ReleaseValidatorResponse(resp) } - - ReleaseValidatorResponse(resp) - } + }) } func Benchmark_validatorPOW_POST(b *testing.B) { @@ -162,13 +164,15 @@ func Benchmark_validatorPOW_POST(b *testing.B) { req.Body = solution b.ResetTimer() - for i := 0; i < b.N; i++ { - resp = AcquireValidatorResponse() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + resp := AcquireValidatorResponse() - if err := validatorPOW(bh, req, resp); err != nil { - b.Errorf("validator failed: %v", err) - } + if err := validatorPOW(bh, req, resp); err != nil { + b.Errorf("validator failed: %v", err) + } - ReleaseValidatorResponse(resp) - } + ReleaseValidatorResponse(resp) + } + }) }