Skip to content

Commit ed07207

Browse files
committed
Add test for configurable timeouts
1 parent b4f79d3 commit ed07207

3 files changed

Lines changed: 70 additions & 10 deletions

File tree

boot.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
const (
1818
serverConfAppName = "deis-builder-server"
1919
gitReceiveConfAppName = "deis-builder-git-receive"
20-
builderPodTick = 100
21-
objectStorageTick = 500
2220
)
2321

2422
func init() {
@@ -61,14 +59,7 @@ func main() {
6159
pkglog.Err("Error getting config for %s [%s]", gitReceiveConfAppName, err)
6260
os.Exit(1)
6361
}
64-
65-
// check for invalid ticks duration
66-
if cnf.BuilderPodTickDurationMSec >= cnf.BuilderPodWaitDurationMSec {
67-
cnf.BuilderPodTickDurationMSec = builderPodTick
68-
}
69-
if cnf.ObjectStorageTickDurationMSec >= cnf.ObjectStorageWaitDurationMSec {
70-
cnf.ObjectStorageTickDurationMSec = objectStorageTick
71-
}
62+
cnf.CheckDurations()
7263

7364
if err := gitreceive.Run(cnf); err != nil {
7465
pkglog.Err("running git receive hook [%s]", err)

pkg/gitreceive/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"time"
66
)
77

8+
const (
9+
builderPodTick = 100
10+
objectStorageTick = 500
11+
)
12+
813
type Config struct {
914
// k8s service discovery env vars
1015
WorkflowHost string `envconfig:"DEIS_WORKFLOW_SERVICE_HOST" required:"true"`
@@ -58,3 +63,21 @@ func (c Config) ObjectStorageTickDuration() time.Duration {
5863
func (c Config) ObjectStorageWaitDuration() time.Duration {
5964
return time.Duration(time.Duration(c.ObjectStorageWaitDurationMSec) * time.Millisecond)
6065
}
66+
67+
// CheckDurations checks if ticks for builder and object storage are not bigger
68+
// than the maximum duration. In case of this it will set the tick to the default
69+
func (c *Config) CheckDurations() {
70+
if c.BuilderPodTickDurationMSec >= c.BuilderPodWaitDurationMSec {
71+
c.BuilderPodTickDurationMSec = builderPodTick
72+
}
73+
if c.BuilderPodTickDurationMSec < builderPodTick {
74+
c.BuilderPodTickDurationMSec = builderPodTick
75+
}
76+
77+
if c.ObjectStorageTickDurationMSec >= c.ObjectStorageWaitDurationMSec {
78+
c.ObjectStorageTickDurationMSec = objectStorageTick
79+
}
80+
if c.ObjectStorageTickDurationMSec < objectStorageTick {
81+
c.ObjectStorageTickDurationMSec = objectStorageTick
82+
}
83+
}

pkg/gitreceive/config_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package gitreceive
2+
3+
import (
4+
"testing"
5+
)
6+
7+
type checkCase struct {
8+
podTick int
9+
podWait int
10+
storageTick int
11+
storageWait int
12+
}
13+
14+
func TestCheckDurations(t *testing.T) {
15+
cases := map[checkCase]checkCase{
16+
checkCase{100, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
17+
checkCase{0, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
18+
checkCase{100, 300000, 0, 300000}: checkCase{100, 300000, 500, 300000},
19+
checkCase{300000, 300000, 500, 300000}: checkCase{100, 300000, 500, 300000},
20+
checkCase{100, 300000, 300000, 300000}: checkCase{100, 300000, 500, 300000},
21+
}
22+
23+
var cnf Config
24+
for tCase, eCase := range cases {
25+
cnf = Config{
26+
BuilderPodTickDurationMSec: tCase.podTick,
27+
BuilderPodWaitDurationMSec: tCase.podWait,
28+
ObjectStorageTickDurationMSec: tCase.storageTick,
29+
ObjectStorageWaitDurationMSec: tCase.storageWait,
30+
}
31+
cnf.CheckDurations()
32+
33+
if cnf.BuilderPodTickDurationMSec != eCase.podTick {
34+
t.Fatalf("expected %v but %v was returned (%v)", eCase.podTick, cnf.BuilderPodTickDurationMSec, tCase)
35+
}
36+
if cnf.BuilderPodWaitDurationMSec != eCase.podWait {
37+
t.Fatalf("expected %v but %v was returned (%v)", eCase.podWait, cnf.BuilderPodWaitDurationMSec, tCase)
38+
}
39+
if cnf.ObjectStorageTickDurationMSec != eCase.storageTick {
40+
t.Fatalf("expected %v but %v was returned (%v)", eCase.storageTick, cnf.ObjectStorageTickDurationMSec, tCase)
41+
}
42+
if cnf.ObjectStorageWaitDurationMSec != eCase.storageWait {
43+
t.Fatalf("expected %v but %v was returned (%v)", eCase.storageWait, cnf.ObjectStorageWaitDurationMSec, tCase)
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)