def test_call_response(self): def respondToEvent(response): # set data field in the response response['newColor'] = int(response['oldColor']) + 1 # start responder OOCSI client # responder = OOCSI('callResponseResponder', 'localhost') responder = OOCSI() # register responder responder.register('colorChannel', 'colorGenerator', respondToEvent) ### test colorGenerator with two calls # start caller OOCSI client #caller = OOCSI('callResponseSender', 'localhost') caller = OOCSI() self.assertTrue(caller.connected) # asynchronous call call1 = caller.call('colorChannel', 'colorGenerator', {'oldColor': 9}, 1) # wait for 500 ms time.sleep(0.5) self.assertEqual(10, call1['response']['newColor']) # blocking call call2 = caller.callAndWait('colorChannel', 'colorGenerator', {'oldColor': 19}, 1) self.assertEqual(20, call2['response']['newColor']) caller.stop() responder.stop()
### test colorGenerator with two calls # start caller OOCSI client #caller = OOCSI('callResponseSender', 'localhost') caller = OOCSI() print(caller.handle) # asynchronous call call1 = caller.call('colorChannel', 'colorGenerator', {'oldColor': 9}, 1) # wait for 1 sec time.sleep(1) # check response in call object if 'response' in call1: print(call1['response']) else: print('response not found') # blocking call call2 = caller.callAndWait('colorChannel', 'colorGenerator', {'oldColor': 19}, 1) # check response in call object directly if 'response' in call2: print(call2['response']) else: print('response not found') caller.stop() responder.stop()