Debian Codegraph @

testing/mozbase/mozcrash/tests/test_symbols_path.py

raw
1 #!/usr/bin/env python
2 # coding=UTF-8
3
4 import zipfile
5 from urllib.parse import urlunsplit
6
7 import mozhttpd
8 import mozunit
9 from conftest import fspath
10 from six import BytesIO
11
12
13 def test_symbols_path_not_present(check_for_crashes, minidump_files):
14 """Test that no symbols path let mozcrash try to find the symbols."""
15 assert 1 == check_for_crashes(symbols_path=None)
16
17
18 def test_symbols_path_unicode(check_for_crashes, minidump_files, tmpdir, capsys):
19 """Test that check_for_crashes can handle unicode in dump_directory."""
20 symbols_path = tmpdir.mkdir("🍪")
21
22 assert 1 == check_for_crashes(symbols_path=fspath(symbols_path), quiet=False)
23
24 out, _ = capsys.readouterr()
25 assert fspath(symbols_path) in out
26
27
28 def test_symbols_path_url(check_for_crashes, minidump_files):
29 """Test that passing a URL as symbols_path correctly fetches the URL."""
30 data = {"retrieved": False}
31
32 def make_zipfile():
33 zdata = BytesIO()
34 z = zipfile.ZipFile(zdata, "w")
35 z.writestr("symbols.txt", "abc/xyz")
36 z.close()
37 return zdata.getvalue()
38
39 def get_symbols(req):
40 data["retrieved"] = True
41
42 headers = {}
43 return (200, headers, make_zipfile())
44
45 httpd = mozhttpd.MozHttpd(
46 port=0,
47 urlhandlers=[{"method": "GET", "path": "/symbols", "function": get_symbols}],
48 )
49 httpd.start()
50 symbol_url = urlunsplit(
51 ("http", "%s:%d" % httpd.httpd.server_address, "/symbols", "", "")
52 )
53
54 assert 1 == check_for_crashes(symbols_path=symbol_url)
55 assert data["retrieved"]
56
57
58 def test_symbols_retry(check_for_crashes, minidump_files):
59 """Test that passing a URL as symbols_path succeeds on retry after temporary HTTP failure."""
60 data = {"retrieved": False}
61 get_symbols_calls = 0
62
63 def make_zipfile():
64 zdata = BytesIO()
65 z = zipfile.ZipFile(zdata, "w")
66 z.writestr("symbols.txt", "abc/xyz")
67 z.close()
68 return zdata.getvalue()
69
70 def get_symbols(req):
71 nonlocal get_symbols_calls
72 data["retrieved"] = True
73 if get_symbols_calls > 0:
74 ret = 200
75 else:
76 ret = 504
77 get_symbols_calls += 1
78
79 headers = {}
80 return (ret, headers, make_zipfile())
81
82 httpd = mozhttpd.MozHttpd(
83 port=0,
84 urlhandlers=[{"method": "GET", "path": "/symbols", "function": get_symbols}],
85 )
86 httpd.start()
87 symbol_url = urlunsplit(
88 ("http", "%s:%d" % httpd.httpd.server_address, "/symbols", "", "")
89 )
90
91 assert 1 == check_for_crashes(symbols_path=symbol_url)
92 assert data["retrieved"]
93 assert 2 == get_symbols_calls
94
95
96 if __name__ == "__main__":
97 mozunit.main()