summaryrefslogtreecommitdiff
path: root/pkg
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 /pkg
parentf648d96c8516652f3231eb87be1f0a000e12793f (diff)
Update worker_watcher stack tests
Diffstat (limited to 'pkg')
-rw-r--r--pkg/worker_watcher/stack_test.go107
1 files changed, 107 insertions, 0 deletions
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