A different approach to forcing foolscap in integration tests.

This commit is contained in:
Itamar Turner-Trauring 2022-12-12 10:43:36 -05:00
parent 66283ade3b
commit 98e25507df
5 changed files with 28 additions and 66 deletions

View File

@ -161,19 +161,21 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- windows-latest
# 22.04 has some issue with Tor at the moment:
# https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3943
- ubuntu-20.04
python-version:
- 3.7
- 3.9
include:
# On macOS don't bother with 3.7, just to get faster builds.
- os: macos-latest
python-version: 3.9
extra-tox-options: ""
- os: windows-latest
python-version: 3.10
extra-tox-options: ""
# 22.04 has some issue with Tor at the moment:
# https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3943
- os: ubuntu-20.04
python-version: 3.8
extra-tox-options: "--force-foolscap integration/"
- os: ubuntu-20.04
python-version: 3.10
extra-tox-options: ""
steps:
- name: Install Tor [Ubuntu]
@ -232,10 +234,7 @@ jobs:
# effect. On Linux it doesn't make a difference one way or another.
TMPDIR: "/tmp"
run: |
# Run with Foolscap forced:
__TAHOE_INTEGRATION_FORCE_FOOLSCAP=1 tox -e integration
# Run with Foolscap not forced, which should result in HTTP being used.
__TAHOE_INTEGRATION_FORCE_FOOLSCAP=0 tox -e integration
tox -e integration ${{ matrix.extra-tox-options }}
- name: Upload eliot.log in case of failure
uses: actions/upload-artifact@v1

View File

@ -1,15 +1,6 @@
"""
Ported to Python 3.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from future.utils import PY2
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
import sys
import shutil
from time import sleep
@ -66,6 +57,13 @@ def pytest_addoption(parser):
"--coverage", action="store_true", dest="coverage",
help="Collect coverage statistics",
)
parser.addoption(
"--force-foolscap", action="store_true", default=False,
dest="force_foolscap",
help=("If set, force Foolscap only for the storage protocol. " +
"Otherwise HTTP will be used.")
)
@pytest.fixture(autouse=True, scope='session')
def eliot_logging():

View File

@ -30,7 +30,6 @@ from allmydata.util.configutil import (
write_config,
)
from allmydata import client
from allmydata.testing import foolscap_only_for_integration_testing
import pytest_twisted
@ -293,14 +292,14 @@ def _create_node(reactor, request, temp_dir, introducer_furl, flog_gatherer, nam
u'log_gatherer.furl',
flog_gatherer,
)
force_foolscap = foolscap_only_for_integration_testing()
if force_foolscap is not None:
set_config(
config,
'storage',
'force_foolscap',
str(force_foolscap),
)
force_foolscap = request.config.getoption("force_foolscap")
assert force_foolscap in (True, False)
set_config(
config,
'storage',
'force_foolscap',
str(force_foolscap),
)
write_config(FilePath(config_path), config)
created_d.addCallback(created)

View File

@ -30,7 +30,6 @@ from foolscap.api import Tub
from .storage.http_server import HTTPServer, build_nurl
from .storage.server import StorageServer
from .testing import foolscap_only_for_integration_testing
class _PretendToBeNegotiation(type):
@ -171,21 +170,6 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
# and later data, otherwise assume HTTPS.
self._timeout.cancel()
if self._buffer.startswith(b"GET /id/"):
if foolscap_only_for_integration_testing() == False:
# Tahoe will prefer HTTP storage protocol over Foolscap when possible.
#
# If this is branch is taken, we are running a test that should
# be using HTTP for the storage protocol. As such, we
# aggressively disable Foolscap to ensure that HTTP is in fact
# going to be used. If we hit this branch that means our
# expectation that HTTP will be used was wrong, suggesting a
# bug in either the code of the integration testing setup.
#
# This branch should never be hit in production!
self.transport.loseConnection()
print("FOOLSCAP IS DISABLED, I PITY THE FOOLS WHO SEE THIS MESSAGE")
return
# We're a Foolscap Negotiation server protocol instance:
transport = self.transport
buf = self._buffer

View File

@ -1,18 +0,0 @@
import os
from typing import Optional
def foolscap_only_for_integration_testing() -> Optional[bool]:
"""
Return whether HTTP storage protocol has been disabled / Foolscap
forced, for purposes of integration testing.
This is determined by the __TAHOE_INTEGRATION_FORCE_FOOLSCAP environment
variable, which can be 1, 0, or not set, corresponding to results of
``True``, ``False`` and ``None`` (i.e. default).
"""
force_foolscap = os.environ.get("__TAHOE_INTEGRATION_FORCE_FOOLSCAP")
if force_foolscap is None:
return None
return bool(int(force_foolscap))