From c45f1eae1404c0198677c9d37b4acca660756731 Mon Sep 17 00:00:00 2001 From: Lee Miller Date: Wed, 27 Dec 2023 04:09:21 +0200 Subject: [PATCH] Test more deterministic commands, add timeouts in get from queue --- src/tests/test_addressgenerator.py | 48 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/src/tests/test_addressgenerator.py b/src/tests/test_addressgenerator.py index 764286e8..236b4d8b 100644 --- a/src/tests/test_addressgenerator.py +++ b/src/tests/test_addressgenerator.py @@ -2,11 +2,15 @@ from binascii import unhexlify +from six.moves import queue + from .partial import TestPartialRun from .samples import ( sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_deterministic_ripe) +TEST_LABEL = 'test' + class TestAddressGenerator(TestPartialRun): """Test case for AddressGenerator thread""" @@ -39,26 +43,44 @@ class TestAddressGenerator(TestPartialRun): def _execute(self, command, *args): self.command_queue.put((command,) + args) try: - return self.return_queue.get()[0] - except IndexError: + return self.return_queue.get(timeout=30)[0] + except (IndexError, queue.Empty): self.fail('Failed to execute command %s' % command) - def test_createChan(self): - """Test createChan command""" + def test_deterministic(self): + """Test deterministic commands""" + self.command_queue.put(( + 'getDeterministicAddress', 3, 1, + TEST_LABEL, 1, sample_seed, False)) + self.assertEqual(sample_deterministic_addr3, self.return_queue.get()) + self.assertEqual( sample_deterministic_addr3, - self._execute('createChan', 3, 1, 'test', sample_seed, True)) - self.assertEqual( - self.worker_queue.get(), - ('sendOutOrStoreMyV3Pubkey', unhexlify(sample_deterministic_ripe))) + self._execute( + 'createDeterministicAddresses', 3, 1, TEST_LABEL, 2, + sample_seed, False, 0, 0)) + + try: + self.assertEqual( + self.worker_queue.get(timeout=30), + ('sendOutOrStoreMyV3Pubkey', + unhexlify(sample_deterministic_ripe))) + + self.worker_queue.get(timeout=30) # get the next addr's task + except queue.Empty: + self.fail('No commands in the worker queue') + self.assertEqual( sample_deterministic_addr4, - self._execute('createChan', 4, 1, 'test', sample_seed, True)) + self._execute('createChan', 4, 1, TEST_LABEL, sample_seed, True)) + try: + self.assertEqual( + self.worker_queue.get(), + ('sendOutOrStoreMyV4Pubkey', sample_deterministic_addr4)) + except queue.Empty: + self.fail('No commands in the worker queue') self.assertEqual( - self.worker_queue.get(), - ('sendOutOrStoreMyV4Pubkey', sample_deterministic_addr4)) - self.assertEqual( - self.config.get(sample_deterministic_addr4, 'label'), 'test') + self.config.get(sample_deterministic_addr4, 'label'), TEST_LABEL) self.assertTrue( self.config.getboolean(sample_deterministic_addr4, 'chan')) self.assertTrue(