Add a test for persistent state and make it pass

This commit is contained in:
Jean-Paul Calderone 2019-11-19 12:56:38 -05:00
parent 8e6aeb49e0
commit 1fef619819
2 changed files with 25 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import hashlib
from mock import Mock
from json import (
dumps,
loads,
)
from fixtures import (
TempDir,
@ -459,6 +460,26 @@ class StoragePluginWebPresence(AsyncTestCase):
result = yield do_http(b"get", url)
self.assertThat(result, Equals(dumps({b"web": b"1"})))
@inlineCallbacks
def test_plugin_resource_persistent_across_requests(self):
"""
The plugin's resource is loaded and then saved and re-used for future
requests.
"""
url = u"http://127.0.0.1:{port}/storage-plugins/{plugin_name}/counter".format(
port=self.port,
plugin_name=self.storage_plugin,
).encode("utf-8")
values = {
loads((yield do_http(b"get", url)))[u"value"],
loads((yield do_http(b"get", url)))[u"value"],
}
self.assertThat(
values,
# If the counter manages to go up then the state stuck around.
Equals({1, 2}),
)
def make_broker(tub_maker=lambda h: Mock()):
"""

View File

@ -29,6 +29,8 @@ class StoragePlugins(Resource, object):
"""
resources = self._client.get_client_storage_plugin_web_resources()
try:
return resources[segment]
result = resources[segment]
except KeyError:
return NoResource()
result = NoResource()
self.putChild(segment, result)
return result