def test_WorkerTable_custom_metrics(c, s, a, b): def metric_port(worker): return worker.port def metric_address(worker): return worker.address metrics = {'metric_port': metric_port, 'metric_address': metric_address} for w in [a, b]: for name, func in metrics.items(): w.metrics[name] = func yield [a.heartbeat(), b.heartbeat()] for w in [a, b]: assert s.workers[w.address].metrics['metric_port'] == w.port assert s.workers[w.address].metrics['metric_address'] == w.address wt = WorkerTable(s) wt.update() data = wt.source.data for name in metrics: assert name in data assert all(data.values()) assert all(len(v) == 2 for v in data.values()) my_index = data['worker'].index(a.address), data['worker'].index(b.address) assert [data['metric_port'][i] for i in my_index] == [a.port, b.port] assert [data['metric_address'][i] for i in my_index] == [a.address, b.address]
def test_WorkerTable(c, s, a, b): wt = WorkerTable(s) wt.update() assert all(wt.source.data.values()) assert all(len(v) == 2 for v in wt.source.data.values()) ncores = wt.source.data["ncores"] assert all(ncores)
def test_WorkerTable_metrics_with_different_metric_2(c, s, a, b): def metric_port(worker): return worker.port a.metrics['metric_a'] = metric_port yield [a.heartbeat(), b.heartbeat()] wt = WorkerTable(s) wt.update() data = wt.source.data assert 'metric_a' in data assert all(data.values()) assert all(len(v) == 2 for v in data.values()) my_index = data['worker'].index(a.address), data['worker'].index(b.address) assert [data['metric_a'][i] for i in my_index] == [a.port, None]
def test_WorkerTable_add_and_remove_metrics(c, s, a, b): def metric_port(worker): return worker.port a.metrics['metric_a'] = metric_port b.metrics['metric_b'] = metric_port yield [a.heartbeat(), b.heartbeat()] assert s.workers[a.address].metrics['metric_a'] == a.port assert s.workers[b.address].metrics['metric_b'] == b.port wt = WorkerTable(s) wt.update() assert 'metric_a' in wt.source.data assert 'metric_b' in wt.source.data # Remove 'metric_b' from worker b del b.metrics['metric_b'] yield [a.heartbeat(), b.heartbeat()] wt = WorkerTable(s) wt.update() assert 'metric_a' in wt.source.data del a.metrics['metric_a'] yield [a.heartbeat(), b.heartbeat()] wt = WorkerTable(s) wt.update() assert 'metric_a' not in wt.source.data
def test_WorkerTable_different_metrics(c, s, a, b): def metric_port(worker): return worker.port a.metrics["metric_a"] = metric_port b.metrics["metric_b"] = metric_port yield [a.heartbeat(), b.heartbeat()] assert s.workers[a.address].metrics["metric_a"] == a.port assert s.workers[b.address].metrics["metric_b"] == b.port wt = WorkerTable(s) wt.update() data = wt.source.data assert "metric_a" in data assert "metric_b" in data assert all(data.values()) assert all(len(v) == 2 for v in data.values()) my_index = data["worker"].index(a.address), data["worker"].index(b.address) assert [data["metric_a"][i] for i in my_index] == [a.port, None] assert [data["metric_b"][i] for i in my_index] == [None, b.port]
def test_WorkerTable(c, s, a, b): wt = WorkerTable(s) wt.update() assert all(wt.source.data.values()) assert all(len(v) == 1 for v in wt.source.data.values())