Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ jobs:
python:
- 3.6
- 3.7
- 3.8
- 3.9
os:
- ubuntu-latest
- macos-latest
tier: [1]
include:
- os: ubuntu-latest
python: 3.8
tier: 1
# - os: macos-latest
# python: 3.8
# tier: 1
- os: windows-latest
python: 3.6
tier: 2
- os: windows-latest
python: 3.7
tier: 2
# these still have some errors:
# - os: windows-latest
# python: 3.8
# - os: windows-latest
# python: 3.9
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -73,7 +71,6 @@ jobs:
run: poetry run make check
- name: Run tests
run: poetry run make tests
continue-on-error: ${{ matrix.tier > 1 }}
- name: Upload coverage
uses: codecov/codecov-action@v1
if: matrix.python == 3.6 && matrix.os == 'ubuntu-latest'
if: matrix.python == 3.7 && matrix.os == 'ubuntu-latest'
8 changes: 6 additions & 2 deletions hathor/cli/top.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# limitations under the License.

import asyncio
import curses
import curses.ascii
import datetime
import signal
import sys
Expand All @@ -26,6 +24,12 @@
from math import floor
from typing import Any, Callable, DefaultDict, Dict, List, Optional, Tuple

try:
import curses
import curses.ascii
except ModuleNotFoundError:
pass

from aiohttp import ClientSession

Key = Tuple[str, ...]
Expand Down
10 changes: 10 additions & 0 deletions tests/cli/test_shell.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import tempfile

import pytest

from hathor.cli.shell import Shell
from tests import unittest

try:
import rocksdb # noqa: F401
except ImportError:
HAS_ROCKSDB = False
else:
HAS_ROCKSDB = True


class ShellTest(unittest.TestCase):
# In this case we just want to go through the code to see if it's okay
Expand All @@ -11,6 +20,7 @@ def test_shell_execution_memory_storage(self):
shell = Shell(argv=['--memory-storage'])
self.assertTrue(shell is not None)

@pytest.mark.skipif(not HAS_ROCKSDB, reason='requires python-rocksdb')
def test_shell_execution_default_storage(self):
temp_data = tempfile.TemporaryDirectory()
shell = Shell(argv=['--data', temp_data.name])
Expand Down
5 changes: 5 additions & 0 deletions tests/p2p/test_connections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import shutil
import sys
import tempfile

import pytest

from hathor.manager import HathorManager
from hathor.transaction.storage import TransactionMemoryStorage
from hathor.wallet import Wallet
Expand All @@ -9,6 +12,8 @@


class ConnectionsTest(unittest.TestCase):

@pytest.mark.skipif(sys.platform == 'win32', reason='run_server is very finicky on Windows')
def test_connections(self):
process = run_server()
process2 = run_server(listen=8006, status=8086, bootstrap='tcp://127.0.0.1:8005')
Expand Down
3 changes: 3 additions & 0 deletions tests/p2p/test_protocol.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import sys

import pytest
import twisted.names.client
from twisted.internet.defer import inlineCallbacks
from twisted.python.failure import Failure
Expand Down Expand Up @@ -155,6 +157,7 @@ def test_valid_hello(self):
self.assertFalse(self.conn.tr1.disconnecting)
self.assertFalse(self.conn.tr2.disconnecting)

@pytest.mark.skipif(sys.platform == 'win32', reason='resolver._parseCall not defined on Windows')
@inlineCallbacks
def test_invalid_peer_id(self):
self.conn.run_one_step() # HELLO
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/test_profiler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
import re
import shutil
import sys
import tempfile

import pytest
from twisted.internet.defer import inlineCallbacks

from hathor.profiler.resources import ProfilerResource
Expand All @@ -14,6 +16,7 @@ def setUp(self):
super().setUp()
self.web = StubSite(ProfilerResource(self.manager))

@pytest.mark.skipif(sys.platform == 'win32', reason='shutil.rmtree fails on Windows')
@inlineCallbacks
def test_post(self):
# Options
Expand Down
4 changes: 4 additions & 0 deletions tests/simulation/test_simulator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import random
import sys
from typing import Optional

import pytest

from hathor.simulator import FakeConnection, MinerSimulator, RandomTransactionGenerator, Simulator
from tests import unittest


@pytest.mark.skipif(sys.platform == 'win32', reason='set_seed fails on Windows')
class HathorSimulatorTestCase(unittest.TestCase):
seed_config: Optional[int] = None

Expand Down
4 changes: 4 additions & 0 deletions tests/tx/test_prometheus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import shutil
import sys
import tempfile

import pytest

from hathor.prometheus import PrometheusMetricsExporter
from tests import unittest
from tests.utils import add_new_blocks, add_new_transactions
Expand All @@ -14,6 +17,7 @@ def setUp(self):
self.network = 'testnet'
self.manager = self.create_peer(self.network, unlock_wallet=True)

@pytest.mark.skipif(sys.platform == 'win32', reason='set_new_metrics fails on Windows')
def test_wallet(self):
tmpdir = tempfile.mkdtemp()
tmpfile = tempfile.NamedTemporaryFile(dir=tmpdir, suffix='.prom', delete=False)
Expand Down
14 changes: 12 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import os
import random
import subprocess
import time
Expand Down Expand Up @@ -192,7 +193,7 @@ def add_blocks_unlock_reward(manager):
return add_new_blocks(manager, settings.REWARD_SPEND_MIN_BLOCKS, advance_clock=1, address=BURN_ADDRESS)


def run_server(hostname='localhost', listen=8005, status=8085, bootstrap=None, tries=100):
def run_server(hostname='localhost', listen=8005, status=8085, bootstrap=None, tries=100, alive_for_at_least_sec=3):
""" Starts a full node in a subprocess running the cli command

:param hostname: Hostname used to be accessed by other peers
Expand Down Expand Up @@ -229,12 +230,21 @@ def run_server(hostname='localhost', listen=8005, status=8085, bootstrap=None, t
if bootstrap:
command = '{} --bootstrap {}'.format(command, bootstrap)

process = subprocess.Popen(command.split())
process = subprocess.Popen(command.split(), env=os.environ)

# check that the process doesn't close in the first few seconds
for _ in range(alive_for_at_least_sec):
exit_code = process.poll()
if exit_code is not None:
raise RuntimeError(f'remote process died with {exit_code}')

partial_url = 'http://{}:{}'.format(hostname, status)
url = urllib.parse.urljoin(partial_url, '/wallet/balance/')
while True:
try:
exit_code = process.poll()
if exit_code is not None:
raise RuntimeError(f'remote process died with {exit_code}')
requests.get(url)
break
except requests.exceptions.ConnectionError:
Expand Down