summaryrefslogtreecommitdiff
path: root/pkg/worker_watcher/stack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/worker_watcher/stack_test.go')
-rw-r--r--pkg/worker_watcher/stack_test.go58
1 files changed, 40 insertions, 18 deletions
diff --git a/pkg/worker_watcher/stack_test.go b/pkg/worker_watcher/stack_test.go
index 7cdb88f1..86af2043 100644
--- a/pkg/worker_watcher/stack_test.go
+++ b/pkg/worker_watcher/stack_test.go
@@ -3,6 +3,7 @@ import (
"context"
"os/exec"
"testing"
+ "time"
"github.com/spiral/roadrunner/v2/interfaces/worker"
workerImpl "github.com/spiral/roadrunner/v2/pkg/worker"
@@ -10,37 +11,37 @@ import (
)
func TestNewWorkersStack(t *testing.T) {
- stack := NewWorkersStack()
- assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ stack := NewWorkersStack(0)
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
assert.Equal(t, []worker.BaseProcess{}, stack.workers)
}
func TestStack_Push(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
w, err := workerImpl.InitBaseWorker(&exec.Cmd{})
assert.NoError(t, err)
stack.Push(w)
- assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(1), stack.actualNumOfWorkers)
}
func TestStack_Pop(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
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, uint64(1), stack.actualNumOfWorkers)
_, _ = stack.Pop()
- assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
}
func TestStack_FindAndRemoveByPid(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
w, err := workerImpl.InitBaseWorker(cmd)
assert.NoError(t, err)
@@ -48,27 +49,27 @@ func TestStack_FindAndRemoveByPid(t *testing.T) {
assert.NoError(t, w.Start())
stack.Push(w)
- assert.Equal(t, int64(1), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(1), stack.actualNumOfWorkers)
stack.FindAndRemoveByPid(w.Pid())
- assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
}
func TestStack_IsEmpty(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
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, uint64(1), stack.actualNumOfWorkers)
assert.Equal(t, false, stack.IsEmpty())
}
func TestStack_Workers(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
w, err := workerImpl.InitBaseWorker(cmd)
assert.NoError(t, err)
@@ -82,20 +83,20 @@ func TestStack_Workers(t *testing.T) {
}
func TestStack_Reset(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
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)
+ assert.Equal(t, uint64(1), stack.actualNumOfWorkers)
stack.Reset()
- assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
}
func TestStack_Destroy(t *testing.T) {
- stack := NewWorkersStack()
+ stack := NewWorkersStack(1)
cmd := exec.Command("php", "../tests/client.php", "echo", "pipes")
w, err := workerImpl.InitBaseWorker(cmd)
assert.NoError(t, err)
@@ -103,5 +104,26 @@ func TestStack_Destroy(t *testing.T) {
stack.Push(w)
stack.Destroy(context.Background())
- assert.Equal(t, int64(0), stack.actualNumOfWorkers)
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
+}
+
+func TestStack_DestroyWithWait(t *testing.T) {
+ stack := NewWorkersStack(2)
+ 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.Push(w)
+ assert.Equal(t, uint64(2), stack.actualNumOfWorkers)
+
+ go func() {
+ wrk, _ := stack.Pop()
+ time.Sleep(time.Second * 3)
+ stack.Push(wrk)
+ }()
+ time.Sleep(time.Second)
+ stack.Destroy(context.Background())
+ assert.Equal(t, uint64(0), stack.actualNumOfWorkers)
}