Onionr/tests/test_onionr_threads.py

42 lines
1.0 KiB
Python
Raw Normal View History

2020-08-05 03:35:45 +00:00
#!/usr/bin/env python3
import sys, os
sys.path.append(".")
sys.path.append("src/")
import unittest, uuid
from time import sleep
TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/'
print("Test directory:", TEST_DIR)
os.environ["ONIONR_HOME"] = TEST_DIR
2020-11-22 00:43:59 +00:00
from utils import createdirs
createdirs.create_dirs()
from onionrcrypto import getourkeypair
getourkeypair.get_keypair()
2020-08-05 03:35:45 +00:00
from coredb import keydb
import onionrsetup as setup
from onionrthreads import add_onionr_thread
2020-11-22 00:43:59 +00:00
2020-08-05 03:35:45 +00:00
setup.setup_config()
class OnionrThreadsTests(unittest.TestCase):
def test_onionr_thread(self):
l = []
def _test_func(obj_list):
obj_list.append(1)
2022-02-10 01:28:31 +00:00
add_onionr_thread(_test_func, 0.05, l, initial_sleep=0)
2020-08-05 03:35:45 +00:00
sleep(0.05)
self.assertGreaterEqual(len(l), 1)
def test_onionr_thread_initial_sleep(self):
l = []
def _test_func(obj_list):
obj_list.append(1)
2022-02-10 01:28:31 +00:00
add_onionr_thread(_test_func, 0.05, l, initial_sleep=1)
2020-08-05 03:35:45 +00:00
self.assertEqual(len(l), 0)
unittest.main()