Try to minimally workaround issues causing Windows to block when writing logs.

This commit is contained in:
Itamar Turner-Trauring 2021-01-21 13:54:22 -05:00
parent 0902c8e156
commit db22291660
3 changed files with 27 additions and 1 deletions

View File

@ -23,7 +23,7 @@ from paramiko.rsakey import RSAKey
import pytest
from .util import generate_ssh_key
from .util import generate_ssh_key, run_in_thread
def connect_sftp(connect_args={"username": "alice", "password": "password"}):
@ -50,6 +50,7 @@ def connect_sftp(connect_args={"username": "alice", "password": "password"}):
return sftp
@run_in_thread
def test_bad_account_password_ssh_key(alice, tmpdir):
"""
Can't login with unknown username, wrong password, or wrong SSH pub key.
@ -79,6 +80,7 @@ def test_bad_account_password_ssh_key(alice, tmpdir):
})
@run_in_thread
def test_ssh_key_auth(alice):
"""It's possible to login authenticating with SSH public key."""
key = RSAKey(filename=join(alice.node_dir, "private", "ssh_client_rsa_key"))
@ -88,6 +90,7 @@ def test_ssh_key_auth(alice):
assert sftp.listdir() == []
@run_in_thread
def test_read_write_files(alice):
"""It's possible to upload and download files."""
sftp = connect_sftp()
@ -102,6 +105,7 @@ def test_read_write_files(alice):
f.close()
@run_in_thread
def test_directories(alice):
"""
It's possible to create, list directories, and create and remove files in
@ -135,6 +139,7 @@ def test_directories(alice):
assert sftp.listdir() == []
@run_in_thread
def test_rename(alice):
"""Directories and files can be renamed."""
sftp = connect_sftp()

View File

@ -178,6 +178,7 @@ def test_deep_stats(alice):
@pytest.mark.timeout(60)
@util.run_in_thread
def test_status(alice):
"""
confirm we get something sensible from /status and the various sub-types

View File

@ -13,10 +13,12 @@ from twisted.python.filepath import (
from twisted.internet.defer import Deferred, succeed
from twisted.internet.protocol import ProcessProtocol
from twisted.internet.error import ProcessExitedAlready, ProcessDone
from twisted.internet.threads import deferToThread
import requests
from paramiko.rsakey import RSAKey
from boltons.funcutils import wraps
from allmydata.util.configutil import (
get_config,
@ -525,3 +527,21 @@ def generate_ssh_key(path):
key.write_private_key_file(path)
with open(path + ".pub", "wb") as f:
f.write(b"%s %s" % (key.get_name(), key.get_base64()))
def run_in_thread(f):
"""Decorator for integration tests that runs code in a thread.
Because we're using pytest_twisted, tests are expected to return a Deferred
so reactor can run. If the reactor doesn't run, reads from nodes' stdout
and stderr don't happen. eventually the buffers fill up, and the nodes
block when they try to flush logs.
We can switch to Twisted APIs (treq instead of requests etc.), but
sometimes it's easier or expedient to just have a block test. So this runs
the test in a thread in a way that still lets the reactor run.
"""
@wraps(f)
def test(*args, **kwargs):
return deferToThread(lambda: f(*args, **kwargs))
return test