Skip to content

Commit

Permalink
tests and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera committed Nov 7, 2023
1 parent 3c342ce commit d7f9a81
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 40 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
8 changes: 1 addition & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
24 changes: 14 additions & 10 deletions identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
})
}
13 changes: 13 additions & 0 deletions internal/tools/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
14 changes: 14 additions & 0 deletions internal/tools/go.sum
Original file line number Diff line number Diff line change
@@ -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=
7 changes: 7 additions & 0 deletions internal/tools/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build tools

package tools

import (
_ "honnef.co/go/tools/cmd/staticcheck"
)
32 changes: 18 additions & 14 deletions validator_pow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
}

0 comments on commit d7f9a81

Please sign in to comment.