diff options
author | Valery Piashchynski <[email protected]> | 2021-06-05 23:10:47 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-05 23:10:47 +0300 |
commit | d24f2346f5fdccb7dd5251dd96d70d76cf6eafa2 (patch) | |
tree | 1965bec227a01c447e49a75badabf95fa090a539 | |
parent | 459e29a85fe5c8571920a602ceb8374bbb893f49 (diff) | |
parent | adfc28833417a49e08cf49b66ff3a829effbdd08 (diff) |
#706 feat(CI): add `Windows` github actions CI
#706 feat(CI): add `Windows` github actions CI
-rw-r--r-- | .github/workflows/linux.yml | 3 | ||||
-rw-r--r-- | .github/workflows/windows.yml | 83 | ||||
-rwxr-xr-x | Makefile | 2 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | pkg/bst/bst_test.go | 69 | ||||
-rw-r--r-- | pkg/pubsub/interface.go | 5 | ||||
-rw-r--r-- | plugins/websockets/storage/storage.go | 90 | ||||
-rw-r--r-- | plugins/websockets/storage/storage_test.go | 299 | ||||
-rw-r--r-- | tests/plugins/metrics/metrics_test.go | 2 |
9 files changed, 95 insertions, 469 deletions
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index a8f97d12..041e6b6e 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,4 +1,4 @@ -name: Tests +name: Linux on: [ push, pull_request ] @@ -63,7 +63,6 @@ jobs: go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/bst.txt -covermode=atomic ./pkg/bst go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/worker_stack.txt -covermode=atomic ./pkg/worker_watcher go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/http_config.txt -covermode=atomic ./plugins/http/config - go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/storage_ws.txt -covermode=atomic ./plugins/websockets/storage go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/http.txt -covermode=atomic ./tests/plugins/http go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/informer.txt -covermode=atomic ./tests/plugins/informer go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage-ci/reload.txt -covermode=atomic ./tests/plugins/reload diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000..759137b5 --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,83 @@ +name: Windows + +on: [ push, pull_request ] + +jobs: + golang: + name: Build (Go ${{ matrix.go }}, PHP ${{ matrix.php }}, OS ${{matrix.os}}) + runs-on: ${{ matrix.os }} + timeout-minutes: 60 + strategy: + fail-fast: true + matrix: + php: [ "8.0" ] + go: [ "1.16" ] + os: [ windows-latest ] + steps: + - name: Set up Go ${{ matrix.go }} + uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go> + with: + go-version: ${{ matrix.go }} + + - name: Set up PHP ${{ matrix.php }} + uses: shivammathur/setup-php@v2 # action page: <https://github.com/shivammathur/setup-php> + with: + php-version: ${{ matrix.php }} + extensions: sockets + + - name: Check out code + uses: actions/checkout@v2 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Init Composer Cache # Docs: <https://git.io/JfAKn#php---composer> + uses: actions/cache@v2 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install Composer dependencies + run: cd tests && composer update --prefer-dist --no-progress --ansi + + - name: Init Go modules Cache # Docs: <https://git.io/JfAKn#go---modules> + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-go- + + - name: Install Go dependencies + run: go mod download + + - name: Run golang tests on Windows + run: | + docker-compose -f ./tests/docker-compose.yaml up -d + mkdir ./coverage-ci + go test -v -race ./pkg/transport/pipe + go test -v -race ./pkg/transport/socket + go test -v -race ./pkg/pool + go test -v -race ./pkg/worker + go test -v -race ./pkg/bst + go test -v -race ./pkg/worker_watcher + go test -v -race ./plugins/http/config + go test -v -race ./tests/plugins/http + go test -v -race ./tests/plugins/informer + go test -v -race ./tests/plugins/reload + go test -v -race ./tests/plugins/server + go test -v -race ./tests/plugins/service + go test -v -race ./tests/plugins/status + go test -v -race ./tests/plugins/config + go test -v -race ./tests/plugins/gzip + go test -v -race ./tests/plugins/headers + go test -v -race ./tests/plugins/logger + go test -v -race ./tests/plugins/metrics + go test -v -race ./tests/plugins/redis + go test -v -race ./tests/plugins/resetter + go test -v -race ./tests/plugins/rpc + go test -v -race ./tests/plugins/kv + go test -v -race ./tests/plugins/websockets + docker-compose -f ./tests/docker-compose.yaml down + cat ./coverage-ci/*.txt > ./coverage-ci/summary.txt @@ -15,7 +15,6 @@ test_coverage: go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/worker_stack.out -covermode=atomic ./pkg/worker_watcher go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/bst.out -covermode=atomic ./pkg/bst go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/http.out -covermode=atomic ./tests/plugins/http - go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/storage-ws.out -covermode=atomic ./plugins/websockets/storage go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/http_config.out -covermode=atomic ./plugins/http/config go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/informer.out -covermode=atomic ./tests/plugins/informer go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/reload.out -covermode=atomic ./tests/plugins/reload @@ -44,7 +43,6 @@ test: ## Run application tests go test -v -race -tags=debug ./pkg/worker_watcher go test -v -race -tags=debug ./pkg/bst go test -v -race -tags=debug ./tests/plugins/http - go test -v -race -tags=debug ./plugins/websockets/storage go test -v -race -tags=debug ./plugins/http/config go test -v -race -tags=debug ./tests/plugins/informer go test -v -race -tags=debug ./tests/plugins/reload @@ -4,7 +4,8 @@ <p align="center"> <a href="https://packagist.org/packages/spiral/roadrunner"><img src="https://poser.pugx.org/spiral/roadrunner/version"></a> <a href="https://pkg.go.dev/github.com/spiral/roadrunner/v2?tab=doc"><img src="https://godoc.org/github.com/spiral/roadrunner/v2?status.svg"></a> - <a href="https://github.com/spiral/roadrunner/actions"><img src="https://github.com/spiral/roadrunner/workflows/Tests/badge.svg" alt=""></a> + <a href="https://github.com/spiral/roadrunner/actions"><img src="https://github.com/spiral/roadrunner/workflows/Linux/badge.svg" alt=""></a> + <a href="https://github.com/spiral/roadrunner/actions"><img src="https://github.com/spiral/roadrunner/workflows/Windows/badge.svg" alt=""></a> <a href="https://github.com/spiral/roadrunner/actions"><img src="https://github.com/spiral/roadrunner/workflows/Linters/badge.svg" alt=""></a> <a href="https://goreportcard.com/report/github.com/spiral/roadrunner"><img src="https://goreportcard.com/badge/github.com/spiral/roadrunner"></a> <a href="https://scrutinizer-ci.com/g/spiral/roadrunner/?branch=master"><img src="https://scrutinizer-ci.com/g/spiral/roadrunner/badges/quality-score.png"></a> @@ -18,10 +19,10 @@ RoadRunner is an open-source (MIT licensed) high-performance PHP application ser It supports running as a service with the ability to extend its functionality on a per-project basis. RoadRunner includes PSR-7/PSR-17 compatible HTTP and HTTP/2 server and can be used to replace classic Nginx+FPM setup -with much greater performance and flexibility. +with much greater performance and flexibility. <p align="center"> - <a href="https://roadrunner.dev/"><b>Official Website</b></a> | + <a href="https://roadrunner.dev/"><b>Official Website</b></a> | <a href="https://roadrunner.dev/docs"><b>Documentation</b></a> | <a href="https://github.com/orgs/spiral/projects/2"><b>Release schedule</b></a> </p> @@ -37,7 +38,7 @@ Features: - No external PHP dependencies (64bit version required), drop-in (based on [Goridge](https://github.com/spiral/goridge)) - Load balancer, process manager and task pipeline - Integrated metrics (Prometheus) -- [Workflow engine](https://github.com/temporalio/sdk-php) by [Temporal.io](https://temporal.io) +- [Workflow engine](https://github.com/temporalio/sdk-php) by [Temporal.io](https://temporal.io) - Works over TCP, UNIX sockets and standard pipes - Automatic worker replacement and safe PHP process destruction - Worker create/allocate/destroy timeouts @@ -64,7 +65,7 @@ $ composer require spiral/roadrunner:v2.0 nyholm/psr7 $ ./vendor/bin/rr get-binary ``` -> For getting roadrunner binary file you can use our docker image: `spiralscout/roadrunner:X.X.X` (more information about +> For getting roadrunner binary file you can use our docker image: `spiralscout/roadrunner:X.X.X` (more information about > image and tags can be found [here](https://hub.docker.com/r/spiralscout/roadrunner/)) Configuration can be located in `.rr.yaml` diff --git a/pkg/bst/bst_test.go b/pkg/bst/bst_test.go index e4d4e4c3..2271508c 100644 --- a/pkg/bst/bst_test.go +++ b/pkg/bst/bst_test.go @@ -323,72 +323,3 @@ func TestBigSearch(t *testing.T) { assert.Len(t, exist, 1) } } - -func TestBigSearchWithRemoves(t *testing.T) { - g1 := NewBST() - g2 := NewBST() - g3 := NewBST() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - t.FailNow() - } - - for i := 0; i < 100000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - for i := 0; i < 100000; i++ { - g2.Insert(uuid.NewString(), uuid.NewString()) - } - for i := 0; i < 100000; i++ { - g3.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 333; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - for i := 0; i < 333; i++ { - g2.Insert(uuid.NewString(), predefinedSlice[333+i]) - } - - for i := 0; i < 333; i++ { - g3.Insert(uuid.NewString(), predefinedSlice[666+i]) - } - - time.Sleep(time.Second * 1) - go func() { - tt := time.NewTicker(time.Second) - for { - select { - case <-tt.C: - num := rand.Intn(333) //nolint:gosec - values := g1.Get(predefinedSlice[num]) - for k := range values { - g1.Remove(k, predefinedSlice[num]) - } - } - } - }() - - for i := 0; i < 333; i++ { - exist := g1.Get(predefinedSlice[i]) - assert.NotNil(t, exist) - assert.Len(t, exist, 1) - } - - for i := 0; i < 333; i++ { - exist := g2.Get(predefinedSlice[333+i]) - assert.NotNil(t, exist) - assert.Len(t, exist, 1) - } - - for i := 0; i < 333; i++ { - exist := g3.Get(predefinedSlice[666+i]) - assert.NotNil(t, exist) - assert.Len(t, exist, 1) - } -} diff --git a/pkg/pubsub/interface.go b/pkg/pubsub/interface.go index 2d5d9595..eb65b4b7 100644 --- a/pkg/pubsub/interface.go +++ b/pkg/pubsub/interface.go @@ -6,7 +6,10 @@ import "github.com/spiral/roadrunner/v2/pkg/pubsub/message" This interface is in BETA. It might be changed. */ -// PubSub ... +// PubSub interface designed to implement on any storage type to provide pub-sub abilities +// Publisher used to receive messages from the PHP app via RPC +// Subscriber should be implemented to subscribe to a topics and provide a connections list per topic +// Reader return next message from the channel type PubSub interface { Publisher Subscriber diff --git a/plugins/websockets/storage/storage.go b/plugins/websockets/storage/storage.go deleted file mode 100644 index 43834658..00000000 --- a/plugins/websockets/storage/storage.go +++ /dev/null @@ -1,90 +0,0 @@ -package storage - -import ( - "sync" - - "github.com/spiral/roadrunner/v2/pkg/bst" -) - -type Storage struct { - sync.RWMutex - BST bst.Storage -} - -func NewStorage() *Storage { - return &Storage{ - BST: bst.NewBST(), - } -} - -func (s *Storage) InsertMany(connID string, topics []string) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - s.BST.Insert(connID, topics[i]) - } -} - -func (s *Storage) Insert(connID string, topic string) { - s.Lock() - defer s.Unlock() - - s.BST.Insert(connID, topic) -} - -func (s *Storage) RemoveMany(connID string, topics []string) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - s.BST.Remove(connID, topics[i]) - } -} - -func (s *Storage) Remove(connID string, topic string) { - s.Lock() - defer s.Unlock() - - s.BST.Remove(connID, topic) -} - -// GetByPtrTS Thread safe get -func (s *Storage) GetByPtrTS(topics []string, res map[string]struct{}) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - d := s.BST.Get(topics[i]) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } - } -} -func (s *Storage) GetOneByPtr(topic string, res map[string]struct{}) { - s.RLock() - defer s.RUnlock() - - d := s.BST.Get(topic) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } -} - -func (s *Storage) GetByPtr(topics []string, res map[string]struct{}) { - s.RLock() - defer s.RUnlock() - - for i := 0; i < len(topics); i++ { - d := s.BST.Get(topics[i]) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } - } -} diff --git a/plugins/websockets/storage/storage_test.go b/plugins/websockets/storage/storage_test.go deleted file mode 100644 index 4072992a..00000000 --- a/plugins/websockets/storage/storage_test.go +++ /dev/null @@ -1,299 +0,0 @@ -package storage - -import ( - "math/rand" - "testing" - "time" - - "github.com/google/uuid" - "github.com/stretchr/testify/assert" -) - -const predifined = "chat-1-2" - -func TestNewBST(t *testing.T) { - // create a new bst - g := NewStorage() - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments"}) - } - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments2"}) - } - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments3"}) - } - - res := make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments"}, res) - assert.Len(t, res, 100) - - res = make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments2"}, res) - assert.Len(t, res, 100) - - res = make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments3"}, res) - assert.Len(t, res, 100) -} - -func BenchmarkGraph(b *testing.B) { - g := NewStorage() - - for i := 0; i < 1000; i++ { - uid := uuid.New().String() - g.InsertMany(uuid.NewString(), []string{uid}) - } - - g.Insert(uuid.NewString(), predifined) - - b.ResetTimer() - b.ReportAllocs() - - res := make(map[string]struct{}) - - for i := 0; i < b.N; i++ { - g.GetByPtr([]string{predifined}, res) - - for i := range res { - delete(res, i) - } - } -} - -func BenchmarkBigSearch(b *testing.B) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - b.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - b.ResetTimer() - b.ReportAllocs() - - res := make(map[string]struct{}, 333) - - for i := 0; i < b.N; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } -} - -func BenchmarkBigSearchWithRemoves(b *testing.B) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - b.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - b.ResetTimer() - b.ReportAllocs() - - go func() { - tt := time.NewTicker(time.Microsecond) - - res := make(map[string]struct{}, 1000) - for { - select { - case <-tt.C: - num := rand.Intn(1000) //nolint:gosec - g1.GetByPtr(predefinedSlice, res) - for k := range res { - g1.Remove(k, predefinedSlice[num]) - } - } - } - }() - - res := make(map[string]struct{}, 100) - - for i := 0; i < b.N; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } -} - -func TestBigSearchWithRemoves(t *testing.T) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - t.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - stopCh := make(chan struct{}) - - go func() { - tt := time.NewTicker(time.Microsecond) - - res := make(map[string]struct{}, 1000) - for { - select { - case <-tt.C: - num := rand.Intn(1000) //nolint:gosec - g1.GetByPtr(predefinedSlice, res) - for k := range res { - g1.Remove(k, predefinedSlice[num]) - } - - case <-stopCh: - tt.Stop() - return - } - } - }() - - res := make(map[string]struct{}, 100) - - for i := 0; i < 1000; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } - - stopCh <- struct{}{} -} - -func TestGraph(t *testing.T) { - g := NewStorage() - - for i := 0; i < 1000; i++ { - uid := uuid.New().String() - g.Insert(uuid.NewString(), uid) - } - - g.Insert(uuid.NewString(), predifined) - - res := make(map[string]struct{}) - - g.GetByPtr([]string{predifined}, res) - assert.NotEmpty(t, res) - assert.Len(t, res, 1) -} - -func TestTreeConcurrentContains(t *testing.T) { - g := NewStorage() - - key1 := uuid.NewString() - key2 := uuid.NewString() - key3 := uuid.NewString() - key4 := uuid.NewString() - key5 := uuid.NewString() - - g.Insert(key1, predifined) - g.Insert(key2, predifined) - g.Insert(key3, predifined) - g.Insert(key4, predifined) - g.Insert(key5, predifined) - - res := make(map[string]struct{}, 100) - - for i := 0; i < 100; i++ { - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - } - - time.Sleep(time.Second * 5) - - res2 := make(map[string]struct{}, 5) - - g.GetByPtr([]string{predifined}, res2) - assert.NotEmpty(t, res2) - assert.Len(t, res2, 5) -} - -func TestGraphRemove(t *testing.T) { - g := NewStorage() - - key1 := uuid.NewString() - key2 := uuid.NewString() - key3 := uuid.NewString() - key4 := uuid.NewString() - key5 := uuid.NewString() - - g.Insert(key1, predifined) - g.Insert(key2, predifined) - g.Insert(key3, predifined) - g.Insert(key4, predifined) - g.Insert(key5, predifined) - - res := make(map[string]struct{}, 5) - g.GetByPtr([]string{predifined}, res) - assert.NotEmpty(t, res) - assert.Len(t, res, 5) - - g.Remove(key1, predifined) - - res2 := make(map[string]struct{}, 4) - g.GetByPtr([]string{predifined}, res2) - assert.NotEmpty(t, res2) - assert.Len(t, res2, 4) -} diff --git a/tests/plugins/metrics/metrics_test.go b/tests/plugins/metrics/metrics_test.go index 8be567ec..3e2023d4 100644 --- a/tests/plugins/metrics/metrics_test.go +++ b/tests/plugins/metrics/metrics_test.go @@ -130,7 +130,7 @@ func TestMetricsIssue571(t *testing.T) { mockLogger.EXPECT().Debug("worker destructed", "pid", gomock.Any()).AnyTimes() mockLogger.EXPECT().Debug("worker constructed", "pid", gomock.Any()).AnyTimes() mockLogger.EXPECT().Debug("Started RPC service", "address", "tcp://127.0.0.1:6001", "services", []string{"metrics"}).MinTimes(1) - mockLogger.EXPECT().Debug("200 GET http://localhost:56444/", "remote", "127.0.0.1", "elapsed", gomock.Any()).MinTimes(1) + mockLogger.EXPECT().Debug("200 GET http://localhost:56444/", "remote", gomock.Any(), "elapsed", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("declaring new metric", "name", "test", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "test", "type", gomock.Any(), "namespace", gomock.Any()).MinTimes(1) mockLogger.EXPECT().Info("metric successfully added", "name", "test", "labels", []string{}, "value", gomock.Any()).MinTimes(1) |