Changeset 07ffde3 in trunk


Ignore:
Timestamp:
2021-11-05T15:13:23Z (3 years ago)
Author:
GitHub <noreply@…>
Branches:
master
Children:
68a27b1, 7faec6e5, bea4cf1, fe6a2f6f
Parents:
8383f6a (diff), b4bc95c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jean-Paul Calderone <exarkun@…> (2021-11-05 15:13:23)
git-committer:
GitHub <noreply@…> (2021-11-05 15:13:23)
Message:

Merge pull request #1158 from tahoe-lafs/3838.more-main-tub-cleanup

More "main tub" initialization cleanup in test code

Fixes: ticket:3838

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/scripts/common.py

    r8383f6a r07ffde3  
    142142    if isinstance(furl, bytes):
    143143        furl = furl.decode("utf-8")
    144     basedir.child(b"private").child(b"introducers.yaml").setContent(
     144    private = basedir.child(b"private")
     145    private.makedirs(ignoreExistingDirectory=True)
     146    private.child(b"introducers.yaml").setContent(
    145147        safe_dump({
    146148            "introducers": {
  • TabularUnified src/allmydata/test/common.py

    r8383f6a r07ffde3  
    268268
    269269    config = attr.ib(default=None)
     270    reactor = attr.ib(default=None)
    270271
    271272    def setUp(self):
     273        self.assigner = SameProcessStreamEndpointAssigner()
     274        self.assigner.setUp()
     275
    272276        def format_config_items(config):
    273277            return "\n".join(
     
    293297            self.introducer_furl,
    294298        )
     299
     300        node_config = self.node_config.copy()
     301        if "tub.port" not in node_config:
     302            if "tub.location" in node_config:
     303                raise ValueError(
     304                    "UseNode fixture does not support specifying tub.location "
     305                    "without tub.port"
     306                )
     307
     308            # Don't use the normal port auto-assignment logic.  It produces
     309            # collisions and makes tests fail spuriously.
     310            tub_location, tub_endpoint = self.assigner.assign(self.reactor)
     311            node_config.update({
     312                "tub.port": tub_endpoint,
     313                "tub.location": tub_location,
     314            })
     315
    295316        self.config = config_from_string(
    296317            self.basedir.asTextMode().path,
     
    305326""".format(
    306327    storage_plugin=self.storage_plugin,
    307     node_config=format_config_items(self.node_config),
     328    node_config=format_config_items(node_config),
    308329    plugin_config_section=plugin_config_section,
    309330)
     
    317338
    318339    def cleanUp(self):
    319         pass
     340        self.assigner.tearDown()
    320341
    321342
  • TabularUnified src/allmydata/test/common_system.py

    r8383f6a r07ffde3  
    768768        config = {}
    769769
    770         except1 = set(range(self.numclients)) - {1}
     770        allclients = set(range(self.numclients))
     771        except1 = allclients - {1}
    771772        feature_matrix = {
    772773            ("client", "nickname"): except1,
    773774
    774             # client 1 has to auto-assign an address.
    775             ("node", "tub.port"): except1,
    776             ("node", "tub.location"): except1,
     775            # Auto-assigning addresses is extremely failure prone and not
     776            # amenable to automated testing in _this_ manner.
     777            ("node", "tub.port"): allclients,
     778            ("node", "tub.location"): allclients,
    777779
    778780            # client 0 runs a webserver and a helper
     
    856858        basedir = FilePath(self.getdir("client%d" % client_num))
    857859        basedir.makedirs()
    858         config = "[client]\n"
     860        config = (
     861            "[node]\n"
     862            "tub.location = {}\n"
     863            "tub.port = {}\n"
     864            "[client]\n"
     865        ).format(*self.port_assigner.assign(reactor))
     866
    859867        if helper_furl:
    860868            config += "helper.furl = %s\n" % helper_furl
  • TabularUnified src/allmydata/test/test_client.py

    r8383f6a r07ffde3  
    9090    MemoryIntroducerClient,
    9191    get_published_announcements,
     92    UseNode,
    9293)
    9394from .matchers import (
     
    954955    @defer.inlineCallbacks
    955956    def test_reloadable(self):
    956         basedir = FilePath("test_client.Run.test_reloadable")
    957         private = basedir.child("private")
    958         private.makedirs()
     957        from twisted.internet import reactor
     958
    959959        dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
    960         write_introducer(basedir, "someintroducer", dummy)
    961         basedir.child("tahoe.cfg").setContent(BASECONFIG. encode("ascii"))
    962         c1 = yield client.create_client(basedir.path)
     960        fixture = UseNode(None, None, FilePath(self.mktemp()), dummy, reactor=reactor)
     961        fixture.setUp()
     962        self.addCleanup(fixture.cleanUp)
     963
     964        c1 = yield fixture.create_node()
    963965        c1.setServiceParent(self.sparent)
    964966
     
    982984        # reactor.stop, also instrument the shutdown event in an
    983985        # attribute that we can check.)
    984         c2 = yield client.create_client(basedir.path)
     986        c2 = yield fixture.create_node()
    985987        c2.setServiceParent(self.sparent)
    986988        yield c2.disownServiceParent()
  • TabularUnified src/allmydata/test/test_node.py

    r8383f6a r07ffde3  
    7070from .common import (
    7171    ConstantAddresses,
     72    SameProcessStreamEndpointAssigner,
     73    UseNode,
    7274)
    7375
     
    8183
    8284# see https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2946
    83 def testing_tub(config_data=''):
     85def testing_tub(reactor, config_data=''):
    8486    """
    8587    Creates a 'main' Tub for testing purposes, from config data
    8688    """
    87     from twisted.internet import reactor
    8889    basedir = 'dummy_basedir'
    8990    config = config_from_string(basedir, 'DEFAULT_PORTNUMFILE_BLANK', config_data)
     
    113114        # conflict with another service to prove it.
    114115        self._available_port = 22
     116        self.port_assigner = SameProcessStreamEndpointAssigner()
     117        self.port_assigner.setUp()
     118        self.addCleanup(self.port_assigner.tearDown)
    115119
    116120    def _test_location(
     
    138142            supply to the system under test as local addresses.
    139143        """
     144        from twisted.internet import reactor
     145
    140146        basedir = self.mktemp()
    141147        create_node_dir(basedir, "testing")
     148        if tub_port is None:
     149            # Always configure a usable tub.port address instead of relying on
     150            # the automatic port assignment.  The automatic port assignment is
     151            # prone to collisions and spurious test failures.
     152            _, tub_port = self.port_assigner.assign(reactor)
     153
    142154        config_data = "[node]\n"
    143         if tub_port:
    144             config_data += "tub.port = {}\n".format(tub_port)
     155        config_data += "tub.port = {}\n".format(tub_port)
     156
     157        # If they wanted a certain location, go for it.  This probably won't
     158        # agree with the tub.port value we set but that only matters if
     159        # anything tries to use this to establish a connection ... which
     160        # nothing in this test suite will.
    145161        if tub_location is not None:
    146162            config_data += "tub.location = {}\n".format(tub_location)
     
    150166                       lambda: local_addresses)
    151167
    152         tub = testing_tub(config_data)
     168        tub = testing_tub(reactor, config_data)
    153169
    154170        class Foo(object):
     
    432448    @defer.inlineCallbacks
    433449    def test_logdir_is_str(self):
    434         basedir = "test_node/test_logdir_is_str"
     450        from twisted.internet import reactor
     451
     452        basedir = FilePath(self.mktemp())
     453        fixture = UseNode(None, None, basedir, "pb://introducer/furl", {}, reactor=reactor)
     454        fixture.setUp()
     455        self.addCleanup(fixture.cleanUp)
    435456
    436457        ns = Namespace()
     
    441462        self.patch(foolscap.logging.log, 'setLogDir', call_setLogDir)
    442463
    443         create_node_dir(basedir, "nothing to see here")
    444         yield client.create_client(basedir)
     464        yield fixture.create_node()
    445465        self.failUnless(ns.called)
    446466
  • TabularUnified src/allmydata/test/web/test_introducer.py

    r8383f6a r07ffde3  
    8484    """
    8585    node.create_node_dir(basedir, "testing")
    86     _, port_endpoint = port_assigner.assign(reactor)
     86    main_tub_location, main_tub_endpoint = port_assigner.assign(reactor)
     87    _, web_port_endpoint = port_assigner.assign(reactor)
    8788    with open(join(basedir, "tahoe.cfg"), "w") as f:
    8889        f.write(
    8990            "[node]\n"
    90             "tub.location = 127.0.0.1:1\n" +
    91             "web.port = {}\n".format(port_endpoint)
     91            "tub.port = {main_tub_endpoint}\n"
     92            "tub.location = {main_tub_location}\n"
     93            "web.port = {web_port_endpoint}\n".format(
     94                main_tub_endpoint=main_tub_endpoint,
     95                main_tub_location=main_tub_location,
     96                web_port_endpoint=web_port_endpoint,
     97            )
    9298        )
    9399
Note: See TracChangeset for help on using the changeset viewer.