summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-01-15 11:36:22 +0300
committerValery Piashchynski <[email protected]>2021-01-15 11:36:22 +0300
commitd37cd690db533e2b8a96e55f11fc798653014e56 (patch)
tree61d20e3b5597fd8843ea9e99d68917e4dd217973
parentf648d96c8516652f3231eb87be1f0a000e12793f (diff)
Update worker_watcher stack tests
-rw-r--r--.github/workflows/build.yml8
-rw-r--r--.vscode/launch.json25
-rw-r--r--.vscode/settings.json15
-rwxr-xr-xMakefile1
-rw-r--r--pkg/worker_watcher/stack_test.go107
5 files changed, 113 insertions, 43 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 1f67b944..97e5feb4 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -18,9 +18,9 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: ["7.4", "8.0"]
- go: ["1.14", "1.15"]
- os: [ubuntu-latest, windows-latest]
+ php: [ "7.4", "8.0" ]
+ go: [ "1.14", "1.15" ]
+ os: [ ubuntu-latest, windows-latest ]
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2 # action page: <https://github.com/actions/setup-go>
@@ -71,6 +71,7 @@ jobs:
go test -v -race -cover -tags=debug ./pkg/pool
go test -v -race -cover -tags=debug ./pkg/socket
go test -v -race -cover -tags=debug ./pkg/worker
+ go test -v -race -cover -tags=debug ./pkg/worker_watcher
go test -v -race -cover -tags=debug ./tests/plugins/http
go test -v -race -cover -tags=debug ./tests/plugins/informer
go test -v -race -cover -tags=debug ./tests/plugins/reload
@@ -103,6 +104,7 @@ jobs:
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/pool.txt -covermode=atomic ./pkg/pool
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/socket.txt -covermode=atomic ./pkg/socket
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/worker.txt -covermode=atomic ./pkg/worker
+ go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/worker_stack.txt -covermode=atomic ./pkg/worker_watcher
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/http.txt -covermode=atomic ./tests/plugins/http
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/informer.txt -covermode=atomic ./tests/plugins/informer
go test -v -race -cover -tags=debug -coverprofile=./coverage-ci/reload.txt -covermode=atomic ./tests/plugins/reload
diff --git a/.vscode/launch.json b/.vscode/launch.json
deleted file mode 100644
index f43ef860..00000000
--- a/.vscode/launch.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- // Use IntelliSense to learn about possible attributes.
- // Hover to view descriptions of existing attributes.
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
- "version": "0.2.0",
- "configurations": [
- {
- "name": "Launch test file",
- "type": "go",
- "request": "launch",
- "mode": "test",
- "program": "${file}"
- },
- {
- "name": "Launch main debug, race",
- "type": "go",
- "request": "launch",
- "mode": "auto",
- "showLog": true,
- "buildFlags": "-race",
- "args": ["serve", "-c", "../.rr.yaml"],
- "program": "${workspaceFolder}/cmd/main.go"
- }
- ]
-} \ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
deleted file mode 100644
index 78560788..00000000
--- a/.vscode/settings.json
+++ /dev/null
@@ -1,15 +0,0 @@
-{
- "workbench.editor.enablePreview": false,
- "go.testFlags": ["-v", "-tags=debug", "-race"],
- "go.lintTool": "golangci-lint",
- "go.lintFlags": [
- "--fast"
- ],
- "cSpell.words": [
- "asdf",
- "bbolt",
- "gofiber",
- "stopc",
- "treshholdc"
- ]
-} \ No newline at end of file
diff --git a/Makefile b/Makefile
index 665c2143..a76dae06 100755
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,7 @@ test: ## Run application tests
go test -v -race -cover -tags=debug -covermode=atomic ./pkg/pool
go test -v -race -cover -tags=debug -covermode=atomic ./pkg/socket
go test -v -race -cover -tags=debug -covermode=atomic ./pkg/worker
+ go test -v -race -cover -tags=debug -covermode=atomic ./pkg/worker_watcher
go test -v -race -cover -tags=debug -covermode=atomic ./tests/plugins/http
go test -v -race -cover -tags=debug -covermode=atomic ./tests/plugins/informer
go test -v -race -cover -tags=debug -covermode=atomic ./tests/plugins/reload
diff --git a/pkg/worker_watcher/stack_test.go b/pkg/worker_watcher/stack_test.go
new file mode 100644
index 00000000..ec02c1d2
--- /dev/null
+++ b/pkg/worker_watcher/stack_test.go
@@ -0,0 +1,107 @@
+package worker_watcher //nolint:golint,stylecheck
+import (
+ "context"
+ "os/exec"
+ "testing"
+
+ "github.com/spiral/roadrunner/v2/interfaces/worker"
+ workerImpl "github.com/spiral/roadrunner/v2/pkg/worker"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestNewWorkersStack(t *testing.T) {
+ stack := NewWorkersStack()
+ assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ assert.Equal(t, []worker.BaseProcess{}, stack.workers)
+}
+
+func TestStack_Push(t *testing.T) {
+ stack := NewWorkersStack()
+
+ w, err := workerImpl.InitBaseWorker(&exec.Cmd{})
+ assert.NoError(t, err)
+
+ stack.Push(w)
+ assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+}
+
+func TestStack_Pop(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+
+ stack.Push(w)
+ assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+
+ _, _ = stack.Pop()
+ assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+}
+
+func TestStack_FindAndRemoveByPid(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+
+ assert.NoError(t, w.Start())
+
+ stack.Push(w)
+ assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+
+ stack.FindAndRemoveByPid(w.Pid())
+ assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+}
+
+func TestStack_IsEmpty(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+
+ stack.Push(w)
+ assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+
+ assert.Equal(t, false, stack.IsEmpty())
+}
+
+func TestStack_Workers(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+ assert.NoError(t, w.Start())
+
+ stack.Push(w)
+
+ wrks := stack.Workers()
+ assert.Equal(t, 1, len(wrks))
+ assert.Equal(t, w.Pid(), wrks[0].Pid())
+}
+
+func TestStack_Reset(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+ assert.NoError(t, w.Start())
+
+ stack.Push(w)
+ assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+ stack.Reset()
+ assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+}
+
+func TestStack_Destroy(t *testing.T) {
+ stack := NewWorkersStack()
+ cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
+ w, err := workerImpl.InitBaseWorker(cmd)
+ assert.NoError(t, err)
+ assert.NoError(t, w.Start())
+
+ stack.Push(w)
+ stack.Destroy(context.Background())
+ assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+} \ No newline at end of file