summaryrefslogtreecommitdiff
path: root/util/state_test.go
blob: 2a4a140bcf609c5b23eea079a70563f0679be00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package util

import (
	"runtime"
	"testing"
	"time"

	"github.com/spiral/roadrunner"
	"github.com/stretchr/testify/assert"
)

func TestServerState(t *testing.T) {
	rr := roadrunner.NewServer(
		&roadrunner.ServerConfig{
			Command:      "php ../tests/client.php echo tcp",
			Relay:        "tcp://:9007",
			RelayTimeout: 10 * time.Second,
			Pool: &roadrunner.Config{
				NumWorkers:      int64(runtime.NumCPU()),
				AllocateTimeout: time.Second,
				DestroyTimeout:  time.Second,
			},
		})
	defer rr.Stop()

	assert.NoError(t, rr.Start())

	state, err := ServerState(rr)
	assert.NoError(t, err)

	assert.Len(t, state, runtime.NumCPU())
}

func TestServerState_Err(t *testing.T) {
	_, err := ServerState(nil)
	assert.Error(t, err)
}