Esempio n. 1
0
def test_reject_recursive_repeats_multithreaded():
    @reject_recursive_repeats
    def recurse(sleep_now):
        time.sleep(sleep_now)
        try:
            recurse(0.05)
            return True
        except ValueError:
            return False
    thd1 = spawn(recurse, 0)
    thd2 = spawn(recurse, 0.02)
    assert thd2.get() and thd1.get()
Esempio n. 2
0
 def request_async(self, raw_method, raw_params):
     request_id = uuid.uuid4()
     self.pending_requests[request_id] = spawn(
         self.request_blocking,
         raw_method=raw_method,
         raw_params=raw_params,
     )
     return request_id
Esempio n. 3
0
 def request_async(self, raw_method, raw_params):
     request_id = uuid.uuid4()
     self.pending_requests[request_id] = spawn(
         self.request_blocking,
         raw_method=raw_method,
         raw_params=raw_params,
     )
     return request_id
Esempio n. 4
0
def test_spawning_simple_thread():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True

    thread = spawn(target_fn)
    thread.join()

    assert container['success'] is True
Esempio n. 5
0
def test_spawning_specific_thread_class():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True

    thread = spawn(target_fn, thread_class=CustomThreadClass)
    thread.join()

    assert isinstance(thread, CustomThreadClass)

    assert container['success'] is True
Esempio n. 6
0
def test_thread_with_return_value():
    container = {
        'success': None,
    }

    def target_fn():
        container['success'] = True
        return 12345

    thread = spawn(target_fn)
    thread.join()

    assert container['success'] is True

    assert thread.get() == 12345
Esempio n. 7
0
    def __init__(self, host="127.0.0.1", port=8545, *args, **kwargs):
        if not is_testrpc_available():
            raise Exception("`TestRPCProvider` requires the `eth-testrpc` package to be installed")
        from testrpc.server import get_application

        application = get_application()

        self.server = make_server(
            host,
            port,
            application,
        )

        self.thread = spawn(self.server.serve_forever)
        endpoint_uri = 'http://{0}:{1}'.format(host, port)

        super(TestRPCProvider, self).__init__(endpoint_uri, *args, **kwargs)
Esempio n. 8
0
    def __init__(self, host="127.0.0.1", port=8545, *args, **kwargs):
        if not is_testrpc_available():
            raise Exception(
                "`TestRPCProvider` requires the `eth-testrpc` package to be installed"
            )
        from testrpc.server import get_application

        application = get_application()

        self.server = make_server(
            host,
            port,
            application,
        )

        self.thread = spawn(self.server.serve_forever)
        endpoint_uri = 'http://{0}:{1}'.format(host, port)

        super().__init__(endpoint_uri, *args, **kwargs)