diff options
Diffstat (limited to 'bitbake/lib/hashserv/tests.py')
| -rw-r--r-- | bitbake/lib/hashserv/tests.py | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/bitbake/lib/hashserv/tests.py b/bitbake/lib/hashserv/tests.py index 869f7636c5..aeedab3575 100644 --- a/bitbake/lib/hashserv/tests.py +++ b/bitbake/lib/hashserv/tests.py | |||
| @@ -810,6 +810,27 @@ class HashEquivalenceCommonTests(object): | |||
| 810 | with self.auth_perms("@user-admin") as client: | 810 | with self.auth_perms("@user-admin") as client: |
| 811 | become = client.become_user(client.username) | 811 | become = client.become_user(client.username) |
| 812 | 812 | ||
| 813 | def test_auth_gc(self): | ||
| 814 | admin_client = self.start_auth_server() | ||
| 815 | |||
| 816 | with self.auth_perms() as client, self.assertRaises(InvokeError): | ||
| 817 | client.gc_mark("ABC", {"unihash": "123"}) | ||
| 818 | |||
| 819 | with self.auth_perms() as client, self.assertRaises(InvokeError): | ||
| 820 | client.gc_status() | ||
| 821 | |||
| 822 | with self.auth_perms() as client, self.assertRaises(InvokeError): | ||
| 823 | client.gc_sweep("ABC") | ||
| 824 | |||
| 825 | with self.auth_perms("@db-admin") as client: | ||
| 826 | client.gc_mark("ABC", {"unihash": "123"}) | ||
| 827 | |||
| 828 | with self.auth_perms("@db-admin") as client: | ||
| 829 | client.gc_status() | ||
| 830 | |||
| 831 | with self.auth_perms("@db-admin") as client: | ||
| 832 | client.gc_sweep("ABC") | ||
| 833 | |||
| 813 | def test_get_db_usage(self): | 834 | def test_get_db_usage(self): |
| 814 | usage = self.client.get_db_usage() | 835 | usage = self.client.get_db_usage() |
| 815 | 836 | ||
| @@ -837,6 +858,147 @@ class HashEquivalenceCommonTests(object): | |||
| 837 | data = client.get_taskhash(self.METHOD, taskhash, True) | 858 | data = client.get_taskhash(self.METHOD, taskhash, True) |
| 838 | self.assertEqual(data["owner"], user["username"]) | 859 | self.assertEqual(data["owner"], user["username"]) |
| 839 | 860 | ||
| 861 | def test_gc(self): | ||
| 862 | taskhash = '53b8dce672cb6d0c73170be43f540460bfc347b4' | ||
| 863 | outhash = '5a9cb1649625f0bf41fc7791b635cd9c2d7118c7f021ba87dcd03f72b67ce7a8' | ||
| 864 | unihash = 'f37918cc02eb5a520b1aff86faacbc0a38124646' | ||
| 865 | |||
| 866 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
| 867 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
| 868 | |||
| 869 | taskhash2 = '3bf6f1e89d26205aec90da04854fbdbf73afe6b4' | ||
| 870 | outhash2 = '77623a549b5b1a31e3732dfa8fe61d7ce5d44b3370f253c5360e136b852967b4' | ||
| 871 | unihash2 = 'af36b199320e611fbb16f1f277d3ee1d619ca58b' | ||
| 872 | |||
| 873 | result = self.client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
| 874 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 875 | |||
| 876 | # Mark the first unihash to be kept | ||
| 877 | ret = self.client.gc_mark("ABC", {"unihash": unihash, "method": self.METHOD}) | ||
| 878 | self.assertEqual(ret, {"count": 1}) | ||
| 879 | |||
| 880 | ret = self.client.gc_status() | ||
| 881 | self.assertEqual(ret, {"mark": "ABC", "keep": 1, "remove": 1}) | ||
| 882 | |||
| 883 | # Second hash is still there; mark doesn't delete hashes | ||
| 884 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 885 | |||
| 886 | ret = self.client.gc_sweep("ABC") | ||
| 887 | self.assertEqual(ret, {"count": 1}) | ||
| 888 | |||
| 889 | # Hash is gone. Taskhash is returned for second hash | ||
| 890 | self.assertClientGetHash(self.client, taskhash2, None) | ||
| 891 | # First hash is still present | ||
| 892 | self.assertClientGetHash(self.client, taskhash, unihash) | ||
| 893 | |||
| 894 | def test_gc_switch_mark(self): | ||
| 895 | taskhash = '53b8dce672cb6d0c73170be43f540460bfc347b4' | ||
| 896 | outhash = '5a9cb1649625f0bf41fc7791b635cd9c2d7118c7f021ba87dcd03f72b67ce7a8' | ||
| 897 | unihash = 'f37918cc02eb5a520b1aff86faacbc0a38124646' | ||
| 898 | |||
| 899 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
| 900 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
| 901 | |||
| 902 | taskhash2 = '3bf6f1e89d26205aec90da04854fbdbf73afe6b4' | ||
| 903 | outhash2 = '77623a549b5b1a31e3732dfa8fe61d7ce5d44b3370f253c5360e136b852967b4' | ||
| 904 | unihash2 = 'af36b199320e611fbb16f1f277d3ee1d619ca58b' | ||
| 905 | |||
| 906 | result = self.client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
| 907 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 908 | |||
| 909 | # Mark the first unihash to be kept | ||
| 910 | ret = self.client.gc_mark("ABC", {"unihash": unihash, "method": self.METHOD}) | ||
| 911 | self.assertEqual(ret, {"count": 1}) | ||
| 912 | |||
| 913 | ret = self.client.gc_status() | ||
| 914 | self.assertEqual(ret, {"mark": "ABC", "keep": 1, "remove": 1}) | ||
| 915 | |||
| 916 | # Second hash is still there; mark doesn't delete hashes | ||
| 917 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 918 | |||
| 919 | # Switch to a different mark and mark the second hash. This will start | ||
| 920 | # a new collection cycle | ||
| 921 | ret = self.client.gc_mark("DEF", {"unihash": unihash2, "method": self.METHOD}) | ||
| 922 | self.assertEqual(ret, {"count": 1}) | ||
| 923 | |||
| 924 | ret = self.client.gc_status() | ||
| 925 | self.assertEqual(ret, {"mark": "DEF", "keep": 1, "remove": 1}) | ||
| 926 | |||
| 927 | # Both hashes are still present | ||
| 928 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 929 | self.assertClientGetHash(self.client, taskhash, unihash) | ||
| 930 | |||
| 931 | # Sweep with the new mark | ||
| 932 | ret = self.client.gc_sweep("DEF") | ||
| 933 | self.assertEqual(ret, {"count": 1}) | ||
| 934 | |||
| 935 | # First hash is gone, second is kept | ||
| 936 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 937 | self.assertClientGetHash(self.client, taskhash, None) | ||
| 938 | |||
| 939 | def test_gc_switch_sweep_mark(self): | ||
| 940 | taskhash = '53b8dce672cb6d0c73170be43f540460bfc347b4' | ||
| 941 | outhash = '5a9cb1649625f0bf41fc7791b635cd9c2d7118c7f021ba87dcd03f72b67ce7a8' | ||
| 942 | unihash = 'f37918cc02eb5a520b1aff86faacbc0a38124646' | ||
| 943 | |||
| 944 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
| 945 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
| 946 | |||
| 947 | taskhash2 = '3bf6f1e89d26205aec90da04854fbdbf73afe6b4' | ||
| 948 | outhash2 = '77623a549b5b1a31e3732dfa8fe61d7ce5d44b3370f253c5360e136b852967b4' | ||
| 949 | unihash2 = 'af36b199320e611fbb16f1f277d3ee1d619ca58b' | ||
| 950 | |||
| 951 | result = self.client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
| 952 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 953 | |||
| 954 | # Mark the first unihash to be kept | ||
| 955 | ret = self.client.gc_mark("ABC", {"unihash": unihash, "method": self.METHOD}) | ||
| 956 | self.assertEqual(ret, {"count": 1}) | ||
| 957 | |||
| 958 | ret = self.client.gc_status() | ||
| 959 | self.assertEqual(ret, {"mark": "ABC", "keep": 1, "remove": 1}) | ||
| 960 | |||
| 961 | # Sweeping with a different mark raises an error | ||
| 962 | with self.assertRaises(InvokeError): | ||
| 963 | self.client.gc_sweep("DEF") | ||
| 964 | |||
| 965 | # Both hashes are present | ||
| 966 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 967 | self.assertClientGetHash(self.client, taskhash, unihash) | ||
| 968 | |||
| 969 | def test_gc_new_hashes(self): | ||
| 970 | taskhash = '53b8dce672cb6d0c73170be43f540460bfc347b4' | ||
| 971 | outhash = '5a9cb1649625f0bf41fc7791b635cd9c2d7118c7f021ba87dcd03f72b67ce7a8' | ||
| 972 | unihash = 'f37918cc02eb5a520b1aff86faacbc0a38124646' | ||
| 973 | |||
| 974 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
| 975 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
| 976 | |||
| 977 | # Start a new garbage collection | ||
| 978 | ret = self.client.gc_mark("ABC", {"unihash": unihash, "method": self.METHOD}) | ||
| 979 | self.assertEqual(ret, {"count": 1}) | ||
| 980 | |||
| 981 | ret = self.client.gc_status() | ||
| 982 | self.assertEqual(ret, {"mark": "ABC", "keep": 1, "remove": 0}) | ||
| 983 | |||
| 984 | # Add second hash. It should inherit the mark from the current garbage | ||
| 985 | # collection operation | ||
| 986 | |||
| 987 | taskhash2 = '3bf6f1e89d26205aec90da04854fbdbf73afe6b4' | ||
| 988 | outhash2 = '77623a549b5b1a31e3732dfa8fe61d7ce5d44b3370f253c5360e136b852967b4' | ||
| 989 | unihash2 = 'af36b199320e611fbb16f1f277d3ee1d619ca58b' | ||
| 990 | |||
| 991 | result = self.client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
| 992 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 993 | |||
| 994 | # Sweep should remove nothing | ||
| 995 | ret = self.client.gc_sweep("ABC") | ||
| 996 | self.assertEqual(ret, {"count": 0}) | ||
| 997 | |||
| 998 | # Both hashes are present | ||
| 999 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 1000 | self.assertClientGetHash(self.client, taskhash, unihash) | ||
| 1001 | |||
| 840 | 1002 | ||
| 841 | class TestHashEquivalenceClient(HashEquivalenceTestSetup, unittest.TestCase): | 1003 | class TestHashEquivalenceClient(HashEquivalenceTestSetup, unittest.TestCase): |
| 842 | def get_server_addr(self, server_idx): | 1004 | def get_server_addr(self, server_idx): |
| @@ -1086,6 +1248,42 @@ class TestHashEquivalenceClient(HashEquivalenceTestSetup, unittest.TestCase): | |||
| 1086 | "get-db-query-columns", | 1248 | "get-db-query-columns", |
| 1087 | ], check=True) | 1249 | ], check=True) |
| 1088 | 1250 | ||
| 1251 | def test_gc(self): | ||
| 1252 | taskhash = '53b8dce672cb6d0c73170be43f540460bfc347b4' | ||
| 1253 | outhash = '5a9cb1649625f0bf41fc7791b635cd9c2d7118c7f021ba87dcd03f72b67ce7a8' | ||
| 1254 | unihash = 'f37918cc02eb5a520b1aff86faacbc0a38124646' | ||
| 1255 | |||
| 1256 | result = self.client.report_unihash(taskhash, self.METHOD, outhash, unihash) | ||
| 1257 | self.assertEqual(result['unihash'], unihash, 'Server returned bad unihash') | ||
| 1258 | |||
| 1259 | taskhash2 = '3bf6f1e89d26205aec90da04854fbdbf73afe6b4' | ||
| 1260 | outhash2 = '77623a549b5b1a31e3732dfa8fe61d7ce5d44b3370f253c5360e136b852967b4' | ||
| 1261 | unihash2 = 'af36b199320e611fbb16f1f277d3ee1d619ca58b' | ||
| 1262 | |||
| 1263 | result = self.client.report_unihash(taskhash2, self.METHOD, outhash2, unihash2) | ||
| 1264 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 1265 | |||
| 1266 | # Mark the first unihash to be kept | ||
| 1267 | self.run_hashclient([ | ||
| 1268 | "--address", self.server_address, | ||
| 1269 | "gc-mark", "ABC", | ||
| 1270 | "--where", "unihash", unihash, | ||
| 1271 | "--where", "method", self.METHOD | ||
| 1272 | ], check=True) | ||
| 1273 | |||
| 1274 | # Second hash is still there; mark doesn't delete hashes | ||
| 1275 | self.assertClientGetHash(self.client, taskhash2, unihash2) | ||
| 1276 | |||
| 1277 | self.run_hashclient([ | ||
| 1278 | "--address", self.server_address, | ||
| 1279 | "gc-sweep", "ABC", | ||
| 1280 | ], check=True) | ||
| 1281 | |||
| 1282 | # Hash is gone. Taskhash is returned for second hash | ||
| 1283 | self.assertClientGetHash(self.client, taskhash2, None) | ||
| 1284 | # First hash is still present | ||
| 1285 | self.assertClientGetHash(self.client, taskhash, unihash) | ||
| 1286 | |||
| 1089 | 1287 | ||
| 1090 | class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase): | 1288 | class TestHashEquivalenceUnixServer(HashEquivalenceTestSetup, HashEquivalenceCommonTests, unittest.TestCase): |
| 1091 | def get_server_addr(self, server_idx): | 1289 | def get_server_addr(self, server_idx): |
