mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-21 02:01:31 +00:00
Run test_system with both Foolscap and HTTP storage protocols, plus some
resulting cleanups.
This commit is contained in:
parent
0f31e3cd4b
commit
42d3843343
@ -5,16 +5,7 @@ in ``allmydata.test.test_system``.
|
||||
Ported to Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
# Don't import bytes since it causes issues on (so far unported) modules on Python 2.
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, dict, list, object, range, max, min, str # noqa: F401
|
||||
|
||||
from typing import Optional
|
||||
import os
|
||||
from functools import partial
|
||||
|
||||
@ -30,6 +21,10 @@ from allmydata import client
|
||||
from allmydata.introducer.server import create_introducer
|
||||
from allmydata.util import fileutil, log, pollmixin
|
||||
from allmydata.storage import http_client
|
||||
from allmydata.storage_client import (
|
||||
NativeStorageServer,
|
||||
HTTPNativeStorageServer,
|
||||
)
|
||||
|
||||
from twisted.python.filepath import (
|
||||
FilePath,
|
||||
@ -646,6 +641,11 @@ def _render_section_values(values):
|
||||
|
||||
class SystemTestMixin(pollmixin.PollMixin, testutil.StallMixin):
|
||||
|
||||
# If set to True, use Foolscap for storage protocol. If set to False, HTTP
|
||||
# will be used when possible. If set to None, this suggests a bug in the
|
||||
# test code.
|
||||
FORCE_FOOLSCAP_FOR_STORAGE : Optional[bool] = None
|
||||
|
||||
def setUp(self):
|
||||
http_client.StorageClient.start_test_mode()
|
||||
self.port_assigner = SameProcessStreamEndpointAssigner()
|
||||
@ -702,7 +702,7 @@ class SystemTestMixin(pollmixin.PollMixin, testutil.StallMixin):
|
||||
return f.read().strip()
|
||||
|
||||
@inlineCallbacks
|
||||
def set_up_nodes(self, NUMCLIENTS=5, force_foolscap=False):
|
||||
def set_up_nodes(self, NUMCLIENTS=5):
|
||||
"""
|
||||
Create an introducer and ``NUMCLIENTS`` client nodes pointed at it. All
|
||||
of the nodes are running in this process.
|
||||
@ -715,18 +715,25 @@ class SystemTestMixin(pollmixin.PollMixin, testutil.StallMixin):
|
||||
|
||||
:param int NUMCLIENTS: The number of client nodes to create.
|
||||
|
||||
:param bool force_foolscap: Force clients to use Foolscap instead of e.g.
|
||||
HTTPS when available.
|
||||
|
||||
:return: A ``Deferred`` that fires when the nodes have connected to
|
||||
each other.
|
||||
"""
|
||||
self.assertIn(
|
||||
self.FORCE_FOOLSCAP_FOR_STORAGE, (True, False),
|
||||
"You forgot to set FORCE_FOOLSCAP_FOR_STORAGE on {}".format(self.__class__)
|
||||
)
|
||||
self.numclients = NUMCLIENTS
|
||||
|
||||
self.introducer = yield self._create_introducer()
|
||||
self.add_service(self.introducer)
|
||||
self.introweb_url = self._get_introducer_web()
|
||||
yield self._set_up_client_nodes(force_foolscap)
|
||||
yield self._set_up_client_nodes(self.FORCE_FOOLSCAP_FOR_STORAGE)
|
||||
native_server = next(iter(self.clients[0].storage_broker.get_known_servers()))
|
||||
if self.FORCE_FOOLSCAP_FOR_STORAGE:
|
||||
expected_storage_server_class = NativeStorageServer
|
||||
else:
|
||||
expected_storage_server_class = HTTPNativeStorageServer
|
||||
self.assertIsInstance(native_server, expected_storage_server_class)
|
||||
|
||||
@inlineCallbacks
|
||||
def _set_up_client_nodes(self, force_foolscap):
|
||||
|
@ -1046,13 +1046,12 @@ class _SharedMixin(SystemTestMixin):
|
||||
"""Base class for Foolscap and HTTP mixins."""
|
||||
|
||||
SKIP_TESTS = set() # type: Set[str]
|
||||
FORCE_FOOLSCAP = False
|
||||
|
||||
def _get_native_server(self):
|
||||
return next(iter(self.clients[0].storage_broker.get_known_servers()))
|
||||
|
||||
def _get_istorage_server(self):
|
||||
raise NotImplementedError("implement in subclass")
|
||||
native_server = next(iter(self.clients[0].storage_broker.get_known_servers()))
|
||||
client = native_server.get_storage_server()
|
||||
self.assertTrue(IStorageServer.providedBy(client))
|
||||
return client
|
||||
|
||||
@inlineCallbacks
|
||||
def setUp(self):
|
||||
@ -1065,7 +1064,7 @@ class _SharedMixin(SystemTestMixin):
|
||||
|
||||
self.basedir = "test_istorageserver/" + self.id()
|
||||
yield SystemTestMixin.setUp(self)
|
||||
yield self.set_up_nodes(1, self.FORCE_FOOLSCAP)
|
||||
yield self.set_up_nodes(1)
|
||||
self.server = None
|
||||
for s in self.clients[0].services:
|
||||
if isinstance(s, StorageServer):
|
||||
@ -1075,7 +1074,7 @@ class _SharedMixin(SystemTestMixin):
|
||||
self._clock = Clock()
|
||||
self._clock.advance(123456)
|
||||
self.server._clock = self._clock
|
||||
self.storage_client = yield self._get_istorage_server()
|
||||
self.storage_client = self._get_istorage_server()
|
||||
|
||||
def fake_time(self):
|
||||
"""Return the current fake, test-controlled, time."""
|
||||
@ -1091,49 +1090,29 @@ class _SharedMixin(SystemTestMixin):
|
||||
yield SystemTestMixin.tearDown(self)
|
||||
|
||||
|
||||
class _FoolscapMixin(_SharedMixin):
|
||||
"""Run tests on Foolscap version of ``IStorageServer``."""
|
||||
|
||||
FORCE_FOOLSCAP = True
|
||||
|
||||
def _get_istorage_server(self):
|
||||
native_server = self._get_native_server()
|
||||
assert isinstance(native_server, NativeStorageServer)
|
||||
client = native_server.get_storage_server()
|
||||
self.assertTrue(IStorageServer.providedBy(client))
|
||||
return succeed(client)
|
||||
|
||||
|
||||
class _HTTPMixin(_SharedMixin):
|
||||
"""Run tests on the HTTP version of ``IStorageServer``."""
|
||||
|
||||
FORCE_FOOLSCAP = False
|
||||
|
||||
def _get_istorage_server(self):
|
||||
native_server = self._get_native_server()
|
||||
assert isinstance(native_server, HTTPNativeStorageServer)
|
||||
client = native_server.get_storage_server()
|
||||
self.assertTrue(IStorageServer.providedBy(client))
|
||||
return succeed(client)
|
||||
|
||||
|
||||
class FoolscapSharedAPIsTests(
|
||||
_FoolscapMixin, IStorageServerSharedAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerSharedAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""Foolscap-specific tests for shared ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = True
|
||||
|
||||
|
||||
class HTTPSharedAPIsTests(
|
||||
_HTTPMixin, IStorageServerSharedAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerSharedAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""HTTP-specific tests for shared ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = False
|
||||
|
||||
|
||||
class FoolscapImmutableAPIsTests(
|
||||
_FoolscapMixin, IStorageServerImmutableAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerImmutableAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""Foolscap-specific tests for immutable ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = True
|
||||
|
||||
def test_disconnection(self):
|
||||
"""
|
||||
If we disconnect in the middle of writing to a bucket, all data is
|
||||
@ -1156,23 +1135,29 @@ class FoolscapImmutableAPIsTests(
|
||||
"""
|
||||
current = self.storage_client
|
||||
yield self.bounce_client(0)
|
||||
self.storage_client = self._get_native_server().get_storage_server()
|
||||
self.storage_client = self._get_istorage_server()
|
||||
assert self.storage_client is not current
|
||||
|
||||
|
||||
class HTTPImmutableAPIsTests(
|
||||
_HTTPMixin, IStorageServerImmutableAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerImmutableAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""HTTP-specific tests for immutable ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = False
|
||||
|
||||
|
||||
class FoolscapMutableAPIsTests(
|
||||
_FoolscapMixin, IStorageServerMutableAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerMutableAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""Foolscap-specific tests for mutable ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = True
|
||||
|
||||
|
||||
class HTTPMutableAPIsTests(
|
||||
_HTTPMixin, IStorageServerMutableAPIsTestsMixin, AsyncTestCase
|
||||
_SharedMixin, IStorageServerMutableAPIsTestsMixin, AsyncTestCase
|
||||
):
|
||||
"""HTTP-specific tests for mutable ``IStorageServer`` APIs."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = False
|
||||
|
@ -117,7 +117,8 @@ class CountingDataUploadable(upload.Data):
|
||||
|
||||
|
||||
class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
|
||||
|
||||
"""Foolscap integration-y tests."""
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = True
|
||||
timeout = 180
|
||||
|
||||
def test_connections(self):
|
||||
@ -1794,6 +1795,7 @@ class SystemTest(SystemTestMixin, RunBinTahoeMixin, unittest.TestCase):
|
||||
|
||||
|
||||
class Connections(SystemTestMixin, unittest.TestCase):
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = True
|
||||
|
||||
def test_rref(self):
|
||||
# The way the listening port is created is via
|
||||
@ -1834,3 +1836,16 @@ class Connections(SystemTestMixin, unittest.TestCase):
|
||||
self.assertEqual(storage_server, self.s1_storage_server)
|
||||
d.addCallback(_down)
|
||||
return d
|
||||
|
||||
|
||||
class HTTPSystemTest(SystemTest):
|
||||
"""HTTP storage protocol variant of the system tests."""
|
||||
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = False
|
||||
|
||||
|
||||
|
||||
class HTTPConnections(Connections):
|
||||
"""HTTP storage protocol variant of the connections tests."""
|
||||
FORCE_FOOLSCAP_FOR_STORAGE = False
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user