|
6 | 6 |
|
7 | 7 | from tests.utils import testutils
|
8 | 8 |
|
9 |
| -from azure_functions_worker.bindings import meta |
10 |
| - |
11 | 9 |
|
12 | 10 | @unittest.skipIf(sys.version_info.minor <= 8, "The base extension"
|
13 | 11 | "is only supported for 3.9+.")
|
@@ -174,16 +172,58 @@ def test_type_undefined(self):
|
174 | 172 | self.assertEqual(r.text, 'test-data')
|
175 | 173 |
|
176 | 174 | def test_caching(self):
|
177 |
| - # Cache is empty at the start |
178 |
| - self.assertEqual(meta.deferred_bindings_cache, {}) |
| 175 | + ''' |
| 176 | + The cache returns the same type based on resource and function name. |
| 177 | + Two different functions with clients that access the same resource |
| 178 | + will have two different clients. This tests that the same client |
| 179 | + is returned for each invocation and that the clients are different |
| 180 | + between the two functions. |
| 181 | + ''' |
| 182 | + |
179 | 183 | r = self.webhost.request('GET', 'blob_cache')
|
| 184 | + r2 = self.webhost.request('GET', 'blob_cache2') |
180 | 185 | self.assertEqual(r.status_code, 200)
|
| 186 | + self.assertEqual(r2.status_code, 200) |
| 187 | + client = r.text |
| 188 | + client2 = r2.text |
| 189 | + self.assertNotEqual(client, client2) |
181 | 190 |
|
182 | 191 | r = self.webhost.request('GET', 'blob_cache')
|
| 192 | + r2 = self.webhost.request('GET', 'blob_cache2') |
183 | 193 | self.assertEqual(r.status_code, 200)
|
| 194 | + self.assertEqual(r2.status_code, 200) |
| 195 | + self.assertEqual(r.text, client) |
| 196 | + self.assertEqual(r2.text, client2) |
| 197 | + self.assertNotEqual(r.text, r2.text) |
184 | 198 |
|
185 | 199 | r = self.webhost.request('GET', 'blob_cache')
|
186 |
| - self.assertEqual(r.status_code, 200) |
| 200 | + r2 = self.webhost.request('GET', 'blob_cache2') |
| 201 | + self.assertEqual(r.status_code, 200) |
| 202 | + self.assertEqual(r2.status_code, 200) |
| 203 | + self.assertEqual(r.text, client) |
| 204 | + self.assertEqual(r2.text, client2) |
| 205 | + self.assertNotEqual(r.text, r2.text) |
| 206 | + |
| 207 | + def test_caching_same_resource(self): |
| 208 | + ''' |
| 209 | + The cache returns the same type based on param name. |
| 210 | + One functions with two clients that access the same resource |
| 211 | + will have two different clients. This tests that the same clients |
| 212 | + are returned for each invocation and that the clients are different |
| 213 | + between the two bindings. |
| 214 | + ''' |
| 215 | + |
| 216 | + r = self.webhost.request('GET', 'blob_cache3') |
| 217 | + self.assertEqual(r.status_code, 200) |
| 218 | + clients = r.text.split(" | ") |
| 219 | + self.assertNotEqual(clients[0], clients[1]) |
| 220 | + |
| 221 | + r2 = self.webhost.request('GET', 'blob_cache3') |
| 222 | + self.assertEqual(r2.status_code, 200) |
| 223 | + clients_second_call = r2.text.split(" | ") |
| 224 | + self.assertEqual(clients[0], clients_second_call[0]) |
| 225 | + self.assertEqual(clients[1], clients_second_call[1]) |
| 226 | + self.assertNotEqual(clients_second_call[0], clients_second_call[1]) |
187 | 227 |
|
188 | 228 | def test_failed_client_creation(self):
|
189 | 229 | r = self.webhost.request('GET', 'invalid_connection_info')
|
|
0 commit comments