async def test_logs(cleanup): worker = {"cls": Worker, "options": {"nthreads": 1}} async with SpecCluster( asynchronous=True, scheduler=scheduler, worker=worker ) as cluster: cluster.scale(2) await cluster logs = await cluster.get_logs() assert is_valid_xml("<div>" + logs._repr_html_() + "</div>") assert "Scheduler" in logs for worker in cluster.scheduler.workers: assert worker in logs assert "Registered" in str(logs) logs = await cluster.get_logs(cluster=True, scheduler=False, workers=False) assert list(logs) == ["Cluster"] logs = await cluster.get_logs(cluster=False, scheduler=True, workers=False) assert list(logs) == ["Scheduler"] logs = await cluster.get_logs(cluster=False, scheduler=False, workers=False) assert list(logs) == [] logs = await cluster.get_logs(cluster=False, scheduler=False, workers=True) assert set(logs) == set(cluster.scheduler.workers) w = toolz.first(cluster.scheduler.workers) logs = await cluster.get_logs(cluster=False, scheduler=False, workers=[w]) assert set(logs) == {w}
async def test_connect(c, s, a, b): future = c.submit(lambda x: x + 1, 1) x = c.submit(slowinc, 1, delay=1, retries=5) await future http_client = AsyncHTTPClient() for suffix in [ "info/main/workers.html", "info/worker/" + url_escape(a.address) + ".html", "info/task/" + url_escape(future.key) + ".html", "info/main/logs.html", "info/logs/" + url_escape(a.address) + ".html", "info/call-stack/" + url_escape(x.key) + ".html", "info/call-stacks/" + url_escape(a.address) + ".html", "json/counts.json", "json/identity.json", "json/index.html", "individual-plots.json", "sitemap.json", ]: response = await http_client.fetch("http://localhost:%d/%s" % (s.http_server.port, suffix)) assert response.code == 200 body = response.body.decode() if suffix.endswith(".json"): json.loads(body) else: assert is_valid_xml(body) assert not re.search("href=./", body) # no absolute links
def test_logs(): log = Log("Hello") assert isinstance(log, str) d = Logs({"123": log, "456": Log("World!")}) assert isinstance(d, dict) text = d._repr_html_() assert is_valid_xml("<div>" + text + "</div>") assert "Hello" in text assert "456" in text
async def test_prefix(c, s, a, b): http_client = AsyncHTTPClient() for suffix in ["foo/info/main/workers.html", "foo/json/index.html", "foo/system"]: response = await http_client.fetch( "http://localhost:%d/%s" % (s.http_server.port, suffix) ) assert response.code == 200 body = response.body.decode() if suffix.endswith(".json"): json.loads(body) else: assert is_valid_xml(body)
def test_is_valid_xml(): assert is_valid_xml("<a>foo</a>") with pytest.raises(Exception): assert is_valid_xml("<a>foo")
def test_logs(): d = Logs({"123": Log("Hello"), "456": Log("World!")}) text = d._repr_html_() assert is_valid_xml("<div>" + text + "</div>") assert "Hello" in text assert "456" in text