def test_image(self): filename = 'images/cloud.jpg' test_filename = 'test_image.jpg' pil_image = PIL.Image.open(filename) c = Client(url = 'http://127.0.0.1:5656', username= '******', verify_ssl=False) config = { 'prompt': 'let there be tests', 'number': 2233, 'input_image': Image(filename) ## Image() supports jpg, png filenames, np.array or PIL.Image } run_response = c.run(config) token = run_response['token'] sleep_and_count(t = 8) resp = c.fetch(token = token) ## check status ideal_status = {'status': 'complete'} print(resp['status']) self.assertTrue(resp['status'] == ideal_status, msg = f"got {resp['status']}") ## save returned image resp['config']['input_image'].save(test_filename) ## check if theyre the same self.assertTrue(PIL.Image.open(test_filename), PIL.Image.open(filename))
def test_update_config(self): filename = 'images/cloud.jpg' pil_image = PIL.Image.open(filename) c = Client(url='http://127.0.0.1:5656', username='******', verify_ssl=False) config = { 'prompt': 'let there be tests', 'number': 2233, 'input_image': Image( filename ) ## Image() supports jpg, png filenames, np.array or PIL.Image } run_response = c.run(config) token = run_response['token'] sleep_and_count(t=2) new_config = { 'prompt': 'updated prompt', 'number': 3322, 'input_image': Image( filename ) ## Image() supports jpg, png filenames, np.array or PIL.Image } resp = c.update_config(token=token, config=new_config) ## chekcing if config was updated successfully ideal_status = 'successfully updated config' self.assertTrue(resp['status'], ideal_status) ## checking if the task is still running resp = c.fetch(token=token) ideal_status_running = 'running' ideal_status_starting = 'starting' print(resp['status']) self.assertTrue((resp['status']['status'] == ideal_status_running) or (resp['status']['status'] == ideal_status_starting)) ## making sure the update config is what its supposed to be ideal_config = { 'prompt': 'updated prompt', 'number': 3322, 'input_image': pil_image ## Image() supports jpg, png filenames, np.array or PIL.Image } print(resp) self.assertTrue(resp['config'], ideal_config)
def test_queue(self): filename = 'images/cloud.jpg' try: queue_data = QueueData(redis_host="0.0.0.0", redis_port=6379, redis_db=0, queue_name='eden_block') except redis.exceptions.ConnectionError: queue_data = QueueData(redis_host="172.17.0.1", redis_port=6379, redis_db=0, queue_name='eden_block') c = Client(url='http://127.0.0.1:5656', username='******', verify_ssl=False) config = { 'prompt': 'let there be tests', 'number': 2233, 'input_image': Image( filename ) ## Image() supports jpg, png filenames, np.array or PIL.Image } self.assertTrue(isinstance(queue_data.redis, Redis)) tokens = [] for i in range(3): token = c.run(config)['token'] tokens.append(token) tokens_in_queue = queue_data.get_queue() print(tokens_in_queue) self.assertTrue(type(tokens_in_queue) == list) if len(tokens_in_queue) > 0: for i in range(len(tokens_in_queue)): self.assertTrue(type(tokens_in_queue[i]) == str) sleep_and_count(1) tokens_in_queue = queue_data.get_queue() for t in tokens: resp = queue_data.get_status(token=t) self.assertTrue(type(resp) == dict) self.assertTrue('status' in list(resp.keys()))
def add_a_task(filename: str): c = Client(url='http://localhost:5656', username='******', verify_ssl=False) config = { 'prompt': 'let there be tests', 'number': 2233, 'input_image': Image(filename ) ## Image() supports jpg, png filenames, np.array or PIL.Image } run_response = c.run(config) return run_response['token']
def test_image(self): filename = 'images/cloud.jpg' test_filename = 'test_image.jpg' pil_image = PIL.Image.open(filename) c = Client(url='http://127.0.0.1:5656', username='******', verify_ssl=False) config = { 'prompt': 'let there be tests', 'number': 2233, 'input_image': Image( filename ) ## Image() supports jpg, png filenames, np.array or PIL.Image } run_response = c.run(config) """ expecting: { 'token': some_long_token, } """ ideal_keys = ['token'] keys_we_got = get_keys(d=run_response) self.assertTrue(ideal_keys, keys_we_got) token = run_response['token'] ## lets spam in a few more task so that we can check queue status for i in range(3): _ = add_a_task(filename=filename) new_token = add_a_task(filename=filename) resp = c.fetch(token=new_token) """ expecting: { 'status': { 'status': queued, 'queue_position': int }, 'config': current_config } """ ideal_keys = ['status', 'config'] keys_we_got = get_keys(d=resp) self.assertTrue(ideal_keys, keys_we_got) ideal_keys = ['status', 'config'] if resp['status']['status'] == 'starting' or resp['status'][ 'status'] == 'queued': self.assertTrue(ideal_keys == keys_we_got) ## waiting for the job to start running while True: resp = c.fetch(token=new_token) sleep_and_count(t=1, reason='waiting for the job to start running... ') if resp['status']['status'] != 'queued' and resp['status'][ 'status'] != 'starting': break """ expected: { 'status': { 'status': 'running', 'progress': float }, config: current_config, 'output': dict } """ resp = c.fetch(token=new_token) ideal_status = 'running' print(resp['status']['status']) self.assertTrue(resp['status']['status'] == ideal_status) self.assertTrue(isinstance(resp['output'], dict)) self.assertTrue(isinstance(resp['status']['progress'], float)) while True: resp = c.fetch(token=new_token) sleep_and_count(t=1, reason='waiting for the job to complete... ') if resp['status']['status'] != 'running': break """ { 'status': { 'status': 'complete' }, 'output': dict, 'config': dict } """ resp = c.fetch(token=new_token) ## making sure status is complete resp = c.fetch(token=new_token) ideal_status = 'complete' self.assertTrue(resp['status']['status'] == ideal_status) ## check returned images in config and output resp['config']['input_image'].save(test_filename) self.assertTrue(PIL.Image.open(test_filename), PIL.Image.open(filename)) ## check returned images in config and output resp['output']['image'].save(test_filename) self.assertTrue(PIL.Image.open(test_filename), PIL.Image.open(filename)) # also check what happens when we send an invalid token resp = c.fetch(token='totally not a valid token') ideal_status = {'status': 'invalid token'} self.assertTrue(resp['status'] == ideal_status)
def stop_server(): c = Client(url = 'http://127.0.0.1:5656', username= '******') c.stop_host(3)
import time from eden.client import Client from eden.datatypes import Image ## set up a client c = Client(url='http://0.0.0.0:5656', username='******') ## define input args to be sent config = { 'prompt': 'let there be light', 'number': 2233, } # start the task run_response = c.run(config) # check status of the task, returns the output too if the task is complete results = c.fetch(token=run_response['token']) print(results) # one eternity later time.sleep(2) ## check status again, hopefully the task is complete by now results = c.fetch(token=run_response['token']) print(results)