-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathactions_test.go
131 lines (110 loc) · 4.1 KB
/
actions_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package vizzini_test
import (
"strconv"
"time"
. "code.cloudfoundry.org/vizzini/matchers"
"code.cloudfoundry.org/bbs/models"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Actions", func() {
var taskDef *models.TaskDefinition
Describe("Timeout action", func() {
BeforeEach(func() {
taskDef = Task()
taskDef.Action = models.WrapAction(models.Timeout(
&models.RunAction{
Path: "bash",
Args: []string{"-c", "sleep 1000"},
User: "vcap",
},
2*time.Second,
))
taskDef.ResultFile = ""
Expect(bbsClient.DesireTask(logger, traceID, guid, domain, taskDef)).To(Succeed())
})
It("should fail the Task within the timeout window", func() {
Eventually(TaskGetter(logger, guid)).Should(HaveTaskState(models.Task_Running))
Eventually(TaskGetter(logger, guid), 10).Should(HaveTaskState(models.Task_Completed))
task, err := bbsClient.TaskByGuid(logger, traceID, guid)
Expect(err).NotTo(HaveOccurred())
Expect(task.GetFailed()).To(BeTrue())
Expect(task.GetFailureReason()).To(ContainSubstring("timeout"))
Expect(bbsClient.ResolvingTask(logger, traceID, guid)).To(Succeed())
Expect(bbsClient.DeleteTask(logger, traceID, guid)).To(Succeed())
})
})
Describe("Run action", func() {
BeforeEach(func() {
taskDef = Task()
taskDef.Action = models.WrapAction(&models.RunAction{
Path: "bash",
Dir: "/etc",
Args: []string{"-c", "echo $PWD > /tmp/bar"},
User: "vcap",
})
Expect(bbsClient.DesireTask(logger, traceID, guid, domain, taskDef)).To(Succeed())
})
It("should be possible to specify a working directory", func() {
Eventually(TaskGetter(logger, guid)).Should(HaveTaskState(models.Task_Completed))
task, err := bbsClient.TaskByGuid(logger, traceID, guid)
Expect(err).NotTo(HaveOccurred())
Expect(task.GetFailed()).To(BeFalse())
Expect(task.GetResult()).To(ContainSubstring("/etc"))
Expect(bbsClient.ResolvingTask(logger, traceID, guid)).To(Succeed())
Expect(bbsClient.DeleteTask(logger, traceID, guid)).To(Succeed())
})
})
Describe("Run action resource limits", func() {
var processLimit uint64 = 23790
BeforeEach(func() {
taskDef = Task()
rl := &models.ResourceLimits{}
rl.SetNofile(processLimit)
taskDef.Action = models.WrapAction(&models.RunAction{
Path: "bash",
Dir: "/etc",
Args: []string{"-c", "ulimit -n > /tmp/bar"},
User: "vcap",
ResourceLimits: rl,
})
Expect(bbsClient.DesireTask(logger, traceID, guid, domain, taskDef)).To(Succeed())
})
It("is possible to limit the number of processes", func() {
Eventually(TaskGetter(logger, guid)).Should(HaveTaskState(models.Task_Completed))
task, err := bbsClient.TaskByGuid(logger, traceID, guid)
Expect(err).NotTo(HaveOccurred())
Expect(task.GetFailed()).To(BeFalse())
Expect(task.GetResult()).To(ContainSubstring(strconv.FormatUint(processLimit, 10)))
Expect(bbsClient.ResolvingTask(logger, traceID, guid)).To(Succeed())
Expect(bbsClient.DeleteTask(logger, traceID, guid)).To(Succeed())
})
})
Describe("Cancelling Downloads", func() {
It("should cancel the download", func() {
desiredLRP := &models.DesiredLRP{
PlacementTags: PlacementTags(),
ProcessGuid: guid,
RootFs: config.DefaultRootFS,
Domain: domain,
Instances: 1,
Action: models.WrapAction(&models.DownloadAction{
From: "https://storage.googleapis.com/diego-assets/large-file.txt",
To: "/tmp",
User: "vcap",
}),
MemoryMb: 128,
DiskMb: 128,
CpuWeight: 100,
LogGuid: guid,
LogSource: "VIZ",
Annotation: "arbitrary-data",
MetricTags: map[string]*models.MetricTagValue{"source_id": {Static: guid}},
}
Expect(bbsClient.DesireLRP(logger, traceID, desiredLRP)).To(Succeed())
Eventually(ActualGetter(logger, desiredLRP.ProcessGuid, 0)).Should(BeActualLRPWithState(desiredLRP.ProcessGuid, 0, "RUNNING"))
Expect(bbsClient.RemoveDesiredLRP(logger, traceID, desiredLRP.ProcessGuid)).To(Succeed())
Eventually(ActualByProcessGuidGetter(logger, desiredLRP.ProcessGuid), 5).Should(BeEmpty())
})
})
})