|
3 | 3 | import StringIO
|
4 | 4 | import sys
|
5 | 5 |
|
| 6 | +import time |
| 7 | + |
6 | 8 | from nose import tools
|
7 | 9 |
|
8 | 10 | from docker_registry.core import exceptions
|
9 | 11 | import docker_registry.testing as testing
|
| 12 | +import docker_registry.testing.mock_boto as mock_boto |
| 13 | +from docker_registry.drivers import s3 |
10 | 14 |
|
11 | 15 | from docker_registry.testing import mock_boto # noqa
|
12 | 16 |
|
@@ -137,3 +141,35 @@ def test_get_tags(self):
|
137 | 141 |
|
138 | 142 | tag_content = store.get_content(tag_path)
|
139 | 143 | assert tag_content == 'randomdata'
|
| 144 | + |
| 145 | + def test_consistency_latency(self): |
| 146 | + self.testCount = -1 |
| 147 | + mockKey = mock_boto.Key() |
| 148 | + def mockExists(): |
| 149 | + self.testCount += 1 |
| 150 | + return self.testCount == 1 |
| 151 | + mockKey.exists = mockExists |
| 152 | + mockKey.get_contents_as_string = lambda: "Foo bar" |
| 153 | + storage = s3.Storage(self.path, self.config) |
| 154 | + storage.makeKey = lambda x: mockKey |
| 155 | + startTime = time.time() |
| 156 | + |
| 157 | + content = storage.get_content("/FOO") |
| 158 | + |
| 159 | + waitTime = time.time() - startTime |
| 160 | + assert waitTime >= 0.1, "Waiting time was less than %sms (actual : %sms)" % (0.1*1000, waitTime*1000) |
| 161 | + assert content == "Foo bar", "expected : %s; actual: %s" % ("Foo bar", content) |
| 162 | + |
| 163 | + @tools.raises(exceptions.FileNotFoundError) |
| 164 | + def test_too_many_read_retries(self): |
| 165 | + self.testCount = -1 |
| 166 | + mockKey = mock_boto.Key() |
| 167 | + def mockExists(): |
| 168 | + self.testCount += 1 |
| 169 | + return self.testCount == 5 |
| 170 | + mockKey.exists = mockExists |
| 171 | + mockKey.get_contents_as_string = lambda: "Foo bar" |
| 172 | + storage = s3.Storage(self.path, self.config) |
| 173 | + storage.makeKey = lambda x: mockKey |
| 174 | + |
| 175 | + storage.get_content("/FOO") |
0 commit comments