-
Notifications
You must be signed in to change notification settings - Fork 1
/
name_spec_test.go
85 lines (71 loc) · 2.21 KB
/
name_spec_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package gang
import (
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
var _ = Describe("GangName", func() {
It("GangNameOf", func() {
pod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "user-0",
Name: "pod-0",
},
}
_, ok := GangNameOf(&pod, gangAnnotationPrefix)
Expect(ok).To(BeFalse())
pod.Annotations = map[string]string{
GangNameAnnotationKey(gangAnnotationPrefix): "gang-0",
}
gn, ok := GangNameOf(&pod, gangAnnotationPrefix)
Expect(ok).To(BeTrue())
Expect(gn).To(Equal(GangName(types.NamespacedName{Namespace: "user-0", Name: "gang-0"})))
})
It("String", func() {
gn := GangName(types.NamespacedName{Namespace: "user-0", Name: "gang-0"})
Expect(gn.String()).To(Equal("user-0/gang-0"))
})
})
var _ = Describe("GangSpec", func() {
It("gangSpecOf", func() {
timeoutConfig := ScheduleTimeoutConfig{
DefaultSeconds: 100,
LimitSeconds: 300,
JitterSeconds: 100,
}
// Default timeout seconds
pod := v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "user-0",
Name: "pod-0",
Annotations: map[string]string{
GangSizeAnnotationKey(gangAnnotationPrefix): "2",
GangNameAnnotationKey(gangAnnotationPrefix): "gang-0",
},
},
}
Expect(gangSpecOf(&pod, timeoutConfig, gangAnnotationPrefix)).To(Equal(GangSpec{
Size: 2,
TimeoutBase: 100 * time.Second,
TimeoutJitterSeconds: 100,
}))
// Specified timeout seconds
pod.Annotations[GangScheduleTimeoutSecondsAnnotationKey(gangAnnotationPrefix)] = "200"
Expect(gangSpecOf(&pod, timeoutConfig, gangAnnotationPrefix)).To(Equal(GangSpec{
Size: 2,
TimeoutBase: 200 * time.Second,
TimeoutJitterSeconds: 100,
}))
// Limited timeout seconds
pod.Annotations[GangScheduleTimeoutSecondsAnnotationKey(gangAnnotationPrefix)] = "400"
Expect(gangSpecOf(&pod, timeoutConfig, gangAnnotationPrefix)).To(Equal(GangSpec{
Size: 2,
TimeoutBase: 300 * time.Second,
TimeoutJitterSeconds: 100,
}))
})
// GangSizeOf and gangScheduleTimeout are tested as part of gangSpecOf
})