def search_files(self, Dir, CompiledRegex): ''' Search all files in Dir and its sub-diectories for the compiled regex ''' FutRets = [] AllMatches = [] nextf = next_file(Dir) next_name = next_i(len(self.Searchers)) for f in nextf: ns = next(next_name) FutRets.append(self.Searchers[ns].search_file(f, CompiledRegex)) try: wait_all(FutRets) except AsyncLocalMaxRetries: ei = exc_info() ftb = format_exception(ei[0], ei[1], ei[2]) raise AsyncRemoteMaxRetries(ei[0].__name__, ei[1], ''.join(ftb)) for FutRet in FutRets: try: File_and_Matches = FutRet.Ret except: print('search_files: Exception: exec_info: {exc_info()}\n') else: if File_and_Matches[1]: AllMatches.append(File_and_Matches) return AllMatches
def run_one_test(self, Servers, Iters): ''' For Iters times issue a request to each of the services. Wait for all requests to complete before testing the results against their expected values. ''' Requests = 0 Errors = 0 FutRets = [] ExpRets = [] for i in range(Iters): for Server in Servers: Arg1, Arg2, Arg3 = i, i * 1.5, 5 FutRet = Server.func_adelic(Arg1, Arg2, Arg3) FutRets.append(FutRet) ExpRets.append(Arg1 + Arg2 + Arg3) try: wait_all(FutRets) except AsyncLocalMaxRetries: ei = exc_info() ftb = format_exception(ei[0], ei[1], ei[2]) raise AsyncRemoteMaxRetries(ei[0].__name__, ei[1], ''.join(ftb)) for FutRet, ExpRet in zip(FutRets, ExpRets): try: Ret = FutRet.Ret except: Errors += 1 print( f'\nC l i e n t {self} E x c e p t i o n : exec_info: {exc_info()}\n' ) if Ret == NoRet: Errors += 1 else: assert Ret == ExpRet Requests += 1 return Requests, Errors
def run_all_tests(self, Server, Iters): ''' Iters times run all of the service's methods. All of the requests against the server are issued concurrently. Process the results after all requests have been issued. ''' print(f'Client {self.my_Name()} starting testing against Service {Server}') # test exception returns by forcing a divide by zero R = Server.d1(0) try: Res = R.Ret except: pass else: print(f'C l i e n t {self.my_Name()} d i d n o t s e e E x c e p t i o n !\n') # regular testing... FutRets = [] ExpRets = [] Test = [] Iter = [] X = TgtBase3() for i in range(Iters): Test.append('inherited foobar0') Iter.append(i) FutRets.append(Server.foobar0(25, 5)) ExpRets.append(X.foobar0(25, 5)) Test.append('inherited foobar1') Iter.append(i) FutRets.append(Server.foobar1(78, 4)) ExpRets.append(X.foobar1(78, 4)) Test.append('inherited foobar2') Iter.append(i) FutRets.append(Server.foobar2(100, 2)) ExpRets.append(X.foobar2(100, 2)) Test.append('overriden foobar3') Iter.append(i) FutRets.append(Server.foobar3(99, 3)) ExpRets.append(X.foobar3(99, 3)) Test.append('method fob, with kwarg used') Iter.append(i) FutRets.append(Server.fob(10, 12, z=25)) ExpRets.append(X.fob(10, 12, z=25)) Test.append('method fob, with kwarg default') Iter.append(i) FutRets.append(Server.fob(10, 12)) ExpRets.append(X.fob(10, 12)) Test.append('pass a list') Iter.append(i) alst = [1, 3, 5, 7, 9, 11, 13, 15] FutRets.append(Server.sumall(alst)) ExpRets.append(X.sumall(alst)) Test.append('pass a function as arg 1') Iter.append(i) FutRets.append(Server.exec_func(sum, alst)) ExpRets.append(X.exec_func(sum, alst)) Test.append('pass a function as arg 2') Iter.append(i) FutRets.append(Server.exec_func(ext_sumall, alst)) ExpRets.append(X.exec_func(ext_sumall, alst)) # Test.append('pass a lambda as arg') # FutRets.append(Server.exec_func(lambda x: sum(x), alst)) # ExpRets.append(X.exec_func(lambda x: sum(x), alst)) Test.append('setattr/getattr, init create') # X was created in __init__and set to 22 Iter.append(i) FutRets.append(Server.X) ExpRets.append(X.X) if i == 0: sleep(.15) # don't want the set to be done before the get in busy conditions, not foolproof Server.X = X.X = 33 Test.append('getattr kwarg, init create') # Y was created in __init__and set using kwarg Iter.append(i) FutRets.append(Server.Y) ExpRets.append(X.Y) Test.append('setattr/getattr, run-time create') # 'b' is being created on first iteration Iter.append(i) if i == 0: Server.b = X.b = 55 sleep(.15) # want the set to be done before the get in busy conditions, not foolproof FutRets.append(Server.b) ExpRets.append(X.b) Val = 222 X.the_a = Val Server.the_a = Val assert Server.the_a == X.the_a Test.append('method with no return') Iter.append(i) FutRets.append(Server.no_return()) ExpRets.append(X.no_return()) Test.append('class as arg') Iter.append(i) FutRets.append(Server.pass_class(TgtBase3)) ExpRets.append(X.pass_class(TgtBase3)) try: wait_all(FutRets) except AsyncLocalMaxRetries: ei = exc_info() ftb = format_exception(ei[0], ei[1], ei[2]) raise AsyncRemoteMaxRetries(ei[0].__name__, ei[1], ''.join(ftb)) Errors = 0 for i in range(len(FutRets)): try: Ret = FutRets[i].Ret except: Errors += 1 print(f'\nC l i e n t {self.my_Name()} E x c e p t i o n : exec_info: {exc_info()} in Test "{Test[i]}" Iter {Iter[i]}\n') else: if Ret == NoRet or Ret != ExpRets[i]: Errors += 1 print(f'\nC l i e n t {self.my_Name()} E r r o r {Ret} vs {ExpRets[i]} in Test "{Test[i]}" Iter {Iter[i]}\n') print(f'Client {self.my_Name()} finished {i+1} Requests with {Errors} Errors') return True