Exemple #1
0
    def test_map(self, instantiate_adapter_executor: SimpleExecutor):
        TestSimpleExecutor._initial()

        instantiate_adapter_executor.map(function=target_function_for_map, args_iter=Test_Function_Args)
        _results = instantiate_adapter_executor.result()
        assert len(_results) == len(Test_Function_Args), ""
        TestSimpleExecutor._chk_run_record(expected_size=len(Test_Function_Args))
Exemple #2
0
    def test_map(self, executor_as_thread: SimpleExecutor):

        TestSimpleExecutor._initial()
        # _args = ("index_1", "index_2", "index_3", "index_4", "index_5")    # Bug 1.
        _args = [("index_1", ), ("index_2", ), ("index_3", ), ("index_4", ),
                 ("index_5", )]

        def _target(*args, **kwargs):
            global Running_Count, Running_Thread_IDs, Running_PPIDs, Running_Current_Threads, Running_Finish_Timestamp

            with _Thread_Lock:
                Running_Count += 1

                if args:
                    if len(args) == 1:
                        assert {args} <= set(
                            _args
                        ), "The argument *args* should be one of element of the input outside."
                    else:
                        assert set(args) <= set(
                            _args
                        ), "The argument *args* should be one of element of the input outside."
                    if len(args) > 1:
                        assert args == _args, "The argument *args* should be same as the global variable 'Test_Function_Args'."
                if kwargs:
                    assert kwargs is None or kwargs == {}, "The argument *kwargs* should be empty or None value."

                _pid = os.getpid()
                _ppid = os.getppid()
                _ident = threading.get_ident()
                # _time = str(datetime.datetime.now())
                _time = int(time.time())

                Running_Thread_IDs.append(_ident)
                Running_PPIDs.append(_ppid)
                Running_Current_Threads.append(str(threading.current_thread()))
                Running_Finish_Timestamp.append(_time)

            time.sleep(Test_Function_Sleep_Time)
            return f"result_{threading.current_thread()}"

        executor_as_thread.map(function=_target, args_iter=_args)
        # Do some checking
        # 1. The amount of workers should be the same with the amount of parameters.
        # 3. The amount of thread IDs should be the same with the amount of parameters.
        # 2. The done-timestamp should be very close.
        TestSimpleExecutor._chk_map_record(len(_args))