MCPcopy Create free account
hub / github.com/apache/mesos / test_list_all

Method test_list_all

src/python/cli_new/lib/cli/tests/task.py:248–310  ·  view source on GitHub ↗

Basic test for the task `list()` sub-command with flag `--all`.

(self)

Source from the content-addressed store, hash-verified

246 master.kill()
247
248 def test_list_all(self):
249 """
250 Basic test for the task `list()` sub-command with flag `--all`.
251 """
252 # Launch a master, agent, and two tasks.
253 master = Master()
254 master.launch()
255
256 agent = Agent()
257 agent.launch()
258
259 task1 = Task({"command": "true"})
260 task1.launch()
261 task1_state = "TASK_FINISHED"
262
263 try:
264 wait_for_task(master, task1.name, task1_state)
265 except Exception as exception:
266 raise CLIException(
267 "Error waiting for task '{name}' to"
268 " reach state '{state}': {error}"
269 .format(name=task1.name, state=task1_state, error=exception))
270
271 task2 = Task({"command": "sleep 1000"})
272 task2.launch()
273 task2_state = "TASK_RUNNING"
274
275 try:
276 wait_for_task(master, task2.name, task2_state)
277 except Exception as exception:
278 raise CLIException(
279 "Error waiting for task '{name}' to"
280 " reach state '{state}': {error}"
281 .format(name=task2.name, state=task2_state, error=exception))
282
283 try:
284 tasks = http.get_json(master.addr, "tasks")["tasks"]
285 except Exception as exception:
286 raise CLIException(
287 "Could not get tasks from '/{endpoint}' on master: {error}"
288 .format(endpoint="tasks", error=exception))
289
290 self.assertEqual(type(tasks), list)
291 self.assertEqual(len(tasks), 2)
292
293 # Invoke the task plugin `list()` command
294 # and parse its output as a table.
295 test_config = config.Config(None)
296 plugin = TaskPlugin(None, test_config)
297 output = capture_output(plugin.list, {"--all": True})
298 table = Table.parse(output)
299
300 # Verify that there are two rows in the table, one for the running task
301 # and one for the finished task. We do verify the information in the
302 # table as this is already covered in the test `test_list`.
303 self.assertEqual(table.dimensions()[0], 3)
304 self.assertEqual(table.dimensions()[1], 4)
305

Callers

nothing calls this directly

Calls 15

launchMethod · 0.95
launchMethod · 0.95
launchMethod · 0.95
killMethod · 0.95
killMethod · 0.95
killMethod · 0.95
MasterClass · 0.90
AgentClass · 0.90
TaskClass · 0.90
wait_for_taskFunction · 0.90
CLIExceptionClass · 0.90
capture_outputFunction · 0.90

Tested by

no test coverage detected