Merge branch '18874-merge-wb2'
[arvados.git] / sdk / cwl / tests / test_fsaccess.py
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 import functools
6 import mock
7 import sys
8 import unittest
9 import json
10 import logging
11 import os
12
13 import arvados
14 import arvados.keep
15 import arvados.collection
16 import arvados_cwl
17
18 from cwltool.pathmapper import MapperEnt
19 from .mock_discovery import get_rootDesc
20
21 from arvados_cwl.fsaccess import CollectionCache
22
23 class TestFsAccess(unittest.TestCase):
24     @mock.patch("arvados.collection.CollectionReader")
25     def test_collection_cache(self, cr):
26         cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
27         c1 = cache.get("99999999999999999999999999999991+99")
28         c2 = cache.get("99999999999999999999999999999991+99")
29         self.assertIs(c1, c2)
30         self.assertEqual(1, cr.call_count)
31         c3 = cache.get("99999999999999999999999999999992+99")
32         self.assertEqual(2, cr.call_count)
33
34     @mock.patch("arvados.collection.CollectionReader")
35     def test_collection_cache_limit(self, cr):
36         cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
37         cr().manifest_text.return_value = 'x' * 524289
38         self.assertEqual(0, cache.total)
39         c1 = cache.get("99999999999999999999999999999991+524289")
40         self.assertIn("99999999999999999999999999999991+524289", cache.collections)
41         self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
42         self.assertEqual((524289*128)*1, cache.total)
43
44         c2 = cache.get("99999999999999999999999999999992+524289")
45         self.assertIn("99999999999999999999999999999991+524289", cache.collections)
46         self.assertIn("99999999999999999999999999999992+524289", cache.collections)
47         self.assertEqual((524289*128)*2, cache.total)
48
49         c1 = cache.get("99999999999999999999999999999991+524289")
50         self.assertIn("99999999999999999999999999999991+524289", cache.collections)
51         self.assertIn("99999999999999999999999999999992+524289", cache.collections)
52         self.assertEqual((524289*128)*2, cache.total)
53
54         c3 = cache.get("99999999999999999999999999999993+524289")
55         self.assertIn("99999999999999999999999999999991+524289", cache.collections)
56         self.assertIn("99999999999999999999999999999992+524289", cache.collections)
57         self.assertEqual((524289*128)*3, cache.total)
58
59         c4 = cache.get("99999999999999999999999999999994+524289")
60         self.assertIn("99999999999999999999999999999991+524289", cache.collections)
61         self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
62         self.assertEqual((524289*128)*3, cache.total)
63
64         c5 = cache.get("99999999999999999999999999999995+524289")
65         self.assertNotIn("99999999999999999999999999999991+524289", cache.collections)
66         self.assertNotIn("99999999999999999999999999999992+524289", cache.collections)
67         self.assertEqual((524289*128)*3, cache.total)
68
69
70     @mock.patch("arvados.collection.CollectionReader")
71     def test_collection_cache_limit2(self, cr):
72         cache = CollectionCache(mock.MagicMock(), mock.MagicMock(), 4)
73         cr().manifest_text.return_value = 'x' * 524287
74         self.assertEqual(0, cache.total)
75         c1 = cache.get("99999999999999999999999999999991+524287")
76         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
77         self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
78         self.assertEqual((524287*128)*1, cache.total)
79
80         c2 = cache.get("99999999999999999999999999999992+524287")
81         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
82         self.assertIn("99999999999999999999999999999992+524287", cache.collections)
83         self.assertEqual((524287*128)*2, cache.total)
84
85         c1 = cache.get("99999999999999999999999999999991+524287")
86         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
87         self.assertIn("99999999999999999999999999999992+524287", cache.collections)
88         self.assertEqual((524287*128)*2, cache.total)
89
90         c3 = cache.get("99999999999999999999999999999993+524287")
91         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
92         self.assertIn("99999999999999999999999999999992+524287", cache.collections)
93         self.assertEqual((524287*128)*3, cache.total)
94
95         c4 = cache.get("99999999999999999999999999999994+524287")
96         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
97         self.assertIn("99999999999999999999999999999992+524287", cache.collections)
98         self.assertEqual((524287*128)*4, cache.total)
99
100         c5 = cache.get("99999999999999999999999999999995+524287")
101         self.assertIn("99999999999999999999999999999991+524287", cache.collections)
102         self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
103         self.assertEqual((524287*128)*4, cache.total)
104
105         c6 = cache.get("99999999999999999999999999999996+524287")
106         self.assertNotIn("99999999999999999999999999999991+524287", cache.collections)
107         self.assertNotIn("99999999999999999999999999999992+524287", cache.collections)
108         self.assertEqual((524287*128)*4, cache.total)