Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 1 addition & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ jobs:
run: make build

- name: Test
run: |
go test -v ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out

- name: check
run: |
echo $GOPATH
pwd
ls -l .
run: make test_coverage

- name: Go Coverage Badge # Pass the `coverage.out` output to this action
uses: tj-actions/coverage-badge-go@v1.2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.idea
test/infra/allocator/config.json
test/allocator/allocator
test/allocator/allocator-test
venv
__pycache__
coverage*out
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ build:
go build ./...
cd ./test/allocator && go build . && cd -

test:
go test -v -count=1 ./...
UNIT_TEST_PACKAGES=$(shell go list ./... | grep -v test)
unit_test:
go test -v -count=1 -cover $(UNIT_TEST_PACKAGES) -coverprofile=coverage.unit.out -coverpkg ./...

integration_test:
go test -c ./test/allocator/main_test.go -o ./test/allocator/allocator-test -coverpkg ./...
./test/allocator/allocator-test -test.v -test.coverprofile=coverage.integration.out

test_coverage: unit_test integration_test
cp coverage.unit.out coverage.overall.out
tail --lines=+2 coverage.integration.out >> coverage.overall.out
go tool cover -func=coverage.overall.out -o=coverage.out

lint:
golangci-lint run -c .golangci.yml ./...
Expand Down
9 changes: 1 addition & 8 deletions backpressure/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,12 @@ import (
var _ Operator = (*OperatorMock)(nil)

type OperatorMock struct {
Operator
mock.Mock
}

func (m *OperatorMock) GetStats() (*stats.BackpressureStats, error) {
panic("implement me")
}

func (m *OperatorMock) SetControlParameters(value *stats.ControlParameters) error {
args := m.Called(value)

return args.Error(0)
}

func (m *OperatorMock) AllowRequest() bool {
panic("implement me")
}
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ require (
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794
github.com/go-logr/logr v1.2.3
github.com/go-logr/stdr v1.2.2
github.com/go-logr/zapr v1.2.3
github.com/golang/protobuf v1.5.2
github.com/pkg/errors v0.9.1
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475
github.com/sajari/regression v1.0.1
github.com/shirou/gopsutil/v3 v3.22.5
github.com/stretchr/testify v1.7.1
github.com/urfave/cli/v2 v2.8.1
github.com/villenny/fastrand64-go v0.0.0-20201008161821-3d8fa521c558
go.uber.org/zap v1.19.0
golang.org/x/time v0.0.0-20220411224347-583f2d630306
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0
Expand All @@ -34,10 +35,12 @@ require (
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect
golang.org/x/text v0.3.7 // indirect
gonum.org/v1/gonum v0.11.0 // indirect
golang.org/x/tools v0.1.9 // indirect
google.golang.org/genproto v0.0.0-20210608205507-b6d2f5bf0d7d // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
94 changes: 19 additions & 75 deletions go.sum

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions test/allocator/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (a *App) Run() {
},
},
Action: func(context *cli.Context) error {
r, err := a.factory.MakeServer(context)
r, err := a.factory.MakeServerFromContext(context)
if err != nil {
return errors.Wrap(err, "make server")
}

return a.runAndWaitSignal(r)
return runAndWaitSignal(r)
},
},
&cli.Command{
Expand All @@ -60,12 +60,12 @@ func (a *App) Run() {
},
},
Action: func(context *cli.Context) error {
r, err := a.factory.MakePerfClient(context)
r, err := a.factory.MakePerfClientFromContext(context)
if err != nil {
return errors.Wrap(err, "make perf client")
}

return a.runAndWaitSignal(r)
return runAndWaitSignal(r)
},
},
},
Expand All @@ -77,7 +77,7 @@ func (a *App) Run() {
}
}

func (a *App) runAndWaitSignal(r Runnable) error {
func runAndWaitSignal(r Runnable) error {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)

Expand Down
22 changes: 14 additions & 8 deletions test/allocator/app/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ type Runnable interface {

// Factory builds runnable tasks.
type Factory interface {
// MakeServer creates a server.
MakeServer(c *cli.Context) (Runnable, error)
// MakePerfClient creates a client for performance tests.
MakePerfClient(c *cli.Context) (Runnable, error)
MakeServerFromConfig(filename string) (Runnable, error)
MakeServerFromContext(c *cli.Context) (Runnable, error)
MakePerfClientFromConfig(filename string) (Runnable, error)
MakePerfClientFromContext(c *cli.Context) (Runnable, error)
}

type factoryDefault struct {
logger logr.Logger
}

//nolint:dupl
func (f *factoryDefault) MakeServer(c *cli.Context) (Runnable, error) {
func (f *factoryDefault) MakeServerFromContext(c *cli.Context) (Runnable, error) {
filename := c.String("config")

return f.MakeServerFromConfig(filename)
}

func (f *factoryDefault) MakeServerFromConfig(filename string) (Runnable, error) {
data, err := ioutil.ReadFile(filepath.Clean(filename))
if err != nil {
return nil, errors.Wrap(err, "ioutil readfile")
Expand All @@ -61,10 +64,13 @@ func (f *factoryDefault) MakeServer(c *cli.Context) (Runnable, error) {
return srv, nil
}

//nolint:dupl
func (f *factoryDefault) MakePerfClient(c *cli.Context) (Runnable, error) {
func (f *factoryDefault) MakePerfClientFromContext(c *cli.Context) (Runnable, error) {
filename := c.String("config")

return f.MakeServerFromConfig(filename)
}

func (f *factoryDefault) MakePerfClientFromConfig(filename string) (Runnable, error) {
data, err := ioutil.ReadFile(filepath.Clean(filename))
if err != nil {
return nil, errors.Wrap(err, "ioutil readfile")
Expand Down
4 changes: 2 additions & 2 deletions test/component_test.go → test/allocator/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: https://github.com/newcloudtechnologies/memlimiter/blob/master/LICENSE
*/

package test
package main

import (
"testing"
Expand Down Expand Up @@ -92,7 +92,7 @@ func makePerfClient(logger logr.Logger, endpoint string) (*perf.Client, error) {
cfg := &perf.Config{
Endpoint: endpoint,
RPS: 100,
LoadDuration: duration.Duration{Duration: 30 * time.Second},
LoadDuration: duration.Duration{Duration: 20 * time.Second},
AllocationSize: bytes.Bytes{Value: bytefmt.MEGABYTE},
PauseDuration: duration.Duration{Duration: 5 * time.Second},
RequestTimeout: duration.Duration{Duration: 1 * time.Minute},
Expand Down
4 changes: 2 additions & 2 deletions test/allocator/perf/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"endpoint": "localhost:1988",
"rps": 100,
"load_duration": "30s",
"load_duration": "20s",
"allocation_size": "1M",
"pause_duration": "5s",
"pause_duration": "10s",
"request_timeout": "1m"
}