Basic test for the task `list()` sub-command.
(self)
| 188 | |
| 189 | |
| 190 | def test_list(self): |
| 191 | """ |
| 192 | Basic test for the task `list()` sub-command. |
| 193 | """ |
| 194 | # Launch a master, agent, and task. |
| 195 | master = Master() |
| 196 | master.launch() |
| 197 | |
| 198 | agent = Agent() |
| 199 | agent.launch() |
| 200 | |
| 201 | task = Task({"command": "sleep 1000"}) |
| 202 | task.launch() |
| 203 | |
| 204 | try: |
| 205 | wait_for_task(master, task.name, "TASK_RUNNING") |
| 206 | except Exception as exception: |
| 207 | raise CLIException( |
| 208 | "Error waiting for task '{name}' to" |
| 209 | " reach state '{state}': {error}" |
| 210 | .format(name=task.name, state="TASK_RUNNING", error=exception)) |
| 211 | |
| 212 | try: |
| 213 | tasks = http.get_json(master.addr, "tasks")["tasks"] |
| 214 | except Exception as exception: |
| 215 | raise CLIException( |
| 216 | "Could not get tasks from '/{endpoint}' on master: {error}" |
| 217 | .format(endpoint="tasks", error=exception)) |
| 218 | |
| 219 | self.assertEqual(type(tasks), list) |
| 220 | self.assertEqual(len(tasks), 1) |
| 221 | |
| 222 | # Invoke the task plugin `list()` command |
| 223 | # and parse its output as a table. |
| 224 | test_config = config.Config(None) |
| 225 | plugin = TaskPlugin(None, test_config) |
| 226 | output = capture_output(plugin.list, {"--all": False}) |
| 227 | table = Table.parse(output) |
| 228 | |
| 229 | # Verify there are two rows in the table |
| 230 | # and that they are formatted as expected, |
| 231 | # with the proper task info in them. |
| 232 | self.assertEqual(table.dimensions()[0], 2) |
| 233 | self.assertEqual(table.dimensions()[1], 4) |
| 234 | self.assertEqual("ID", table[0][0]) |
| 235 | self.assertEqual("State", table[0][1]) |
| 236 | self.assertEqual("Framework ID", table[0][2]) |
| 237 | self.assertEqual("Executor ID", table[0][3]) |
| 238 | self.assertEqual(tasks[0]["id"], table[1][0]) |
| 239 | self.assertEqual(tasks[0]["statuses"][-1]["state"], table[1][1]) |
| 240 | self.assertEqual(tasks[0]["framework_id"], table[1][2]) |
| 241 | self.assertEqual(tasks[0]["executor_id"], table[1][3]) |
| 242 | |
| 243 | # Kill the task, agent, and master. |
| 244 | task.kill() |
| 245 | agent.kill() |
| 246 | master.kill() |
| 247 |
nothing calls this directly
no test coverage detected