OLD | NEW |
1 package swarming | 1 package swarming |
2 | 2 |
3 import ( | 3 import ( |
4 "encoding/json" | 4 "encoding/json" |
5 "fmt" | 5 "fmt" |
6 "io/ioutil" | 6 "io/ioutil" |
7 "path" | 7 "path" |
8 "path/filepath" | 8 "path/filepath" |
9 "strings" | 9 "strings" |
10 "testing" | 10 "testing" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 assert.Nil(t, err) | 99 assert.Nil(t, err) |
100 assert.Equal(t, 2, len(tasksToHashes)) | 100 assert.Equal(t, 2, len(tasksToHashes)) |
101 for _, taskName := range taskNames { | 101 for _, taskName := range taskNames { |
102 hash, exists := tasksToHashes[taskName] | 102 hash, exists := tasksToHashes[taskName] |
103 assert.True(t, exists) | 103 assert.True(t, exists) |
104 assert.NotNil(t, hash) | 104 assert.NotNil(t, hash) |
105 } | 105 } |
106 | 106 |
107 // Trigger swarming using the isolate hashes. | 107 // Trigger swarming using the isolate hashes. |
108 dimensions := map[string]string{"pool": "Chrome"} | 108 dimensions := map[string]string{"pool": "Chrome"} |
109 » tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, RECOMMEN
DED_PRIORITY, RECOMMENDED_EXPIRATION, false) | 109 » tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, RECOMMEN
DED_PRIORITY, RECOMMENDED_EXPIRATION, RECOMMENDED_HARD_TIMEOUT, RECOMMENDED_IO_T
IMEOUT, false) |
110 assert.Nil(t, err) | 110 assert.Nil(t, err) |
111 | 111 |
112 // Collect both output and file output of all tasks. | 112 // Collect both output and file output of all tasks. |
113 for _, task := range tasks { | 113 for _, task := range tasks { |
114 output, outputDir, err := task.Collect(s) | 114 output, outputDir, err := task.Collect(s) |
115 assert.Nil(t, err) | 115 assert.Nil(t, err) |
116 output = sanitizeOutput(output) | 116 output = sanitizeOutput(output) |
117 assert.Equal(t, fmt.Sprintf("arg_1_%s\narg_2_%s\n", task.Title,
task.Title), output) | 117 assert.Equal(t, fmt.Sprintf("arg_1_%s\narg_2_%s\n", task.Title,
task.Title), output) |
118 // Verify contents of the outputDir. | 118 // Verify contents of the outputDir. |
119 rawFileOutput, err := ioutil.ReadFile(path.Join(outputDir, "outp
ut.txt")) | 119 rawFileOutput, err := ioutil.ReadFile(path.Join(outputDir, "outp
ut.txt")) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 assert.Nil(t, err) | 161 assert.Nil(t, err) |
162 assert.Equal(t, 2, len(tasksToHashes)) | 162 assert.Equal(t, 2, len(tasksToHashes)) |
163 for _, taskName := range taskNames { | 163 for _, taskName := range taskNames { |
164 hash, exists := tasksToHashes[taskName] | 164 hash, exists := tasksToHashes[taskName] |
165 assert.True(t, exists) | 165 assert.True(t, exists) |
166 assert.NotNil(t, hash) | 166 assert.NotNil(t, hash) |
167 } | 167 } |
168 | 168 |
169 // Trigger swarming using the isolate hashes. | 169 // Trigger swarming using the isolate hashes. |
170 dimensions := map[string]string{"pool": "Chrome"} | 170 dimensions := map[string]string{"pool": "Chrome"} |
171 » tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, RECOMMEN
DED_PRIORITY, RECOMMENDED_EXPIRATION, false) | 171 » tasks, err := s.TriggerSwarmingTasks(tasksToHashes, dimensions, RECOMMEN
DED_PRIORITY, RECOMMENDED_EXPIRATION, RECOMMENDED_HARD_TIMEOUT, RECOMMENDED_IO_T
IMEOUT, false) |
172 assert.Nil(t, err) | 172 assert.Nil(t, err) |
173 | 173 |
174 // Collect testTask1. It should have failed. | 174 // Collect testTask1. It should have failed. |
175 output1, outputDir1, err1 := tasks[0].Collect(s) | 175 output1, outputDir1, err1 := tasks[0].Collect(s) |
176 output1 = sanitizeOutput(output1) | 176 output1 = sanitizeOutput(output1) |
177 assert.Equal(t, "", output1) | 177 assert.Equal(t, "", output1) |
178 assert.Equal(t, "", outputDir1) | 178 assert.Equal(t, "", outputDir1) |
179 assert.NotNil(t, err1) | 179 assert.NotNil(t, err1) |
180 assert.True(t, strings.HasPrefix(err1.Error(), "Swarming trigger for tes
tTask1 failed with: Command exited with exit status 1: ")) | 180 assert.True(t, strings.HasPrefix(err1.Error(), "Swarming trigger for tes
tTask1 failed with: Command exited with exit status 1: ")) |
181 | 181 |
182 // Collect testTask2. It should have succeeded. | 182 // Collect testTask2. It should have succeeded. |
183 output2, outputDir2, err2 := tasks[1].Collect(s) | 183 output2, outputDir2, err2 := tasks[1].Collect(s) |
184 assert.Nil(t, err2) | 184 assert.Nil(t, err2) |
185 output2 = sanitizeOutput(output2) | 185 output2 = sanitizeOutput(output2) |
186 assert.Equal(t, fmt.Sprintf("arg_1_%s\narg_2_%s\n", tasks[1].Title, task
s[1].Title), output2) | 186 assert.Equal(t, fmt.Sprintf("arg_1_%s\narg_2_%s\n", tasks[1].Title, task
s[1].Title), output2) |
187 // Verify contents of the outputDir. | 187 // Verify contents of the outputDir. |
188 rawFileOutput, err := ioutil.ReadFile(path.Join(outputDir2, "output.txt"
)) | 188 rawFileOutput, err := ioutil.ReadFile(path.Join(outputDir2, "output.txt"
)) |
189 assert.Nil(t, err) | 189 assert.Nil(t, err) |
190 fileOutput := strings.Replace(string(rawFileOutput), "\r\n", "\n", -1) | 190 fileOutput := strings.Replace(string(rawFileOutput), "\r\n", "\n", -1) |
191 assert.Equal(t, "testing\ntesting", fileOutput) | 191 assert.Equal(t, "testing\ntesting", fileOutput) |
192 } | 192 } |
193 | 193 |
194 // sanitizeOutput makes the task output consistent. Sometimes the outputs comes | 194 // sanitizeOutput makes the task output consistent. Sometimes the outputs comes |
195 // back with "\r\n" and sometimes with "\n". This function makes it always be "\
n". | 195 // back with "\r\n" and sometimes with "\n". This function makes it always be "\
n". |
196 func sanitizeOutput(output string) string { | 196 func sanitizeOutput(output string) string { |
197 return strings.Replace(output, "\r\n", "\n", -1) | 197 return strings.Replace(output, "\r\n", "\n", -1) |
198 } | 198 } |
OLD | NEW |