summaryrefslogtreecommitdiff
path: root/pool_test.go
blob: 998dd9d49c30d52df0c58c285a4289ea9d978efe (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package roadrunner

import (
	"testing"
	"time"

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

func Test_NumWorkers(t *testing.T) {
	cfg := Config{
		AllocateTimeout: time.Second,
		DestroyTimeout:  time.Second * 10,
	}
	err := cfg.Valid()

	assert.NotNil(t, err)
	assert.Equal(t, "pool.NumWorkers must be set", err.Error())
}

func Test_NumWorkers_Default(t *testing.T) {
	cfg := Config{
		AllocateTimeout: time.Second,
		DestroyTimeout:  time.Second * 10,
		ExecTTL:         time.Second * 5,
	}

	assert.NoError(t, cfg.InitDefaults())
	err := cfg.Valid()
	assert.Nil(t, err)
}

func Test_AllocateTimeout(t *testing.T) {
	cfg := Config{
		NumWorkers:     10,
		DestroyTimeout: time.Second * 10,
	}
	err := cfg.Valid()

	assert.NotNil(t, err)
	assert.Equal(t, "pool.AllocateTimeout must be set", err.Error())
}

func Test_DestroyTimeout(t *testing.T) {
	cfg := Config{
		NumWorkers:      10,
		AllocateTimeout: time.Second,
	}
	err := cfg.Valid()

	assert.NotNil(t, err)
	assert.Equal(t, "pool.DestroyTimeout must be set", err.Error())
}