Ejemplo n.º 1
0
class TestManagedThread(unittest.TestCase):
    def setUp(self):
        def mock_target():
            threading.current_thread().wait()

        self.thread = ManagedThread(target=mock_target)

    def tearDown(self):
        pass

    def test_init(self):
        self.assertTrue(self.thread.daemon)
        self.assertFalse(self.thread.attached_event.is_set())

    def test_wake(self):
        self.thread.start()
        self.assertTrue(self.thread.is_alive())
        self.thread.wake()
        self.assertTrue(self.thread.attached_event.is_set())
        self.thread.join()
        self.assertFalse(self.thread.is_alive())
Ejemplo n.º 2
0
class TestManagedThread(unittest.TestCase):

    def setUp(self):
        def mock_target():
            threading.current_thread().wait()

        self.thread = ManagedThread(target=mock_target)

    def tearDown(self):
        pass

    def test_init(self):
        self.assertTrue(self.thread.daemon)
        self.assertFalse(self.thread.attached_event.is_set())

    def test_wake(self):
        self.thread.start()
        self.assertTrue(self.thread.is_alive())
        self.thread.wake()
        self.assertTrue(self.thread.attached_event.is_set())
        self.thread.join()
        self.assertFalse(self.thread.is_alive())
Ejemplo n.º 3
0
 def setUp(self):
     self.server_url = 'https://test.url/'
     self.api_path = '/api/downstream/v1'
     self.size = 100
     self.address = base58.b58encode_check(b'\x00' + os.urandom(20))
     self.token = binascii.hexlify(os.urandom(16)).decode('ascii')
     self.msg = ''
     self.sig = ''
     self.thread_manager = ShellApplication()
     self.contract_thread = ManagedThread()
     self.chunk_dir = os.path.join('data', 'chunks')
     self.client = DownstreamClient(self.server_url, self.token,
                                    self.address, self.size, self.msg,
                                    self.sig, self.thread_manager,
                                    self.chunk_dir)
     self.client.session = mock.MagicMock()
     self.test_contract = \
         DownstreamContract(self.client,
                            MockValues.get_chunks_response[
                                'chunks'][0]['file_hash'],
                            MockValues.get_chunks_response[
                                'chunks'][0]['seed'],
                            MockValues.get_chunks_response[
                                'chunks'][0]['size'],
                            Heartbeat.challenge_type().fromdict(
                                MockValues
                                .get_chunks_response
                                ['chunks'][0]['challenge']),
                            datetime.utcnow() + timedelta(
                                seconds=int(
                                    MockValues
                                    .get_chunks_response
                                    ['chunks'][0]['due'])),
                            Heartbeat.tag_type().fromdict(
                                MockValues
                                .get_chunks_response
                                ['chunks'][0]['tag']),
                            self.thread_manager,
                            self.chunk_dir)
     self.test_heartbeat = Heartbeat.fromdict(
         MockValues.connect_response['heartbeat'])
Ejemplo n.º 4
0
    def setUp(self):
        def mock_target():
            threading.current_thread().wait()

        self.thread = ManagedThread(target=mock_target)
Ejemplo n.º 5
0
    def setUp(self):
        def mock_target():
            threading.current_thread().wait()

        self.thread = ManagedThread(target=mock_target)