How to use run_server method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

test_rpc.py

Source:test_rpc.py Github

copy

Full Screen

...14 """15 Run a basic mock tests.16 """17 rpc_event = multiprocessing.Event()18 def run_server():19 class MockServer(Server):20 @rpc_method21 def mock_method(self):22 return {'success': True}23 MockServer(socket_dir=socket_dir).run()24 def run_client():25 mock_client = Client(socket_dir=socket_dir)26 response = mock_client.call('mock_server', 'mock_method')27 if response['success']:28 rpc_event.set()29 multiprocessing.Process(target=run_server, daemon=True).start()30 multiprocessing.Process(target=run_client, daemon=True).start()31 assert rpc_event.wait(1)32def test_reliability_client(socket_dir):33 """34 Test client reliability on server crash.35 """36 crash_event = multiprocessing.Event()37 rpc_event = multiprocessing.Event()38 def run_server():39 class MockServer(Server):40 @rpc_method41 def mock_method(self):42 if not crash_event.is_set():43 crash_event.set()44 sys.exit(1)45 else:46 return {'success': True}47 MockServer(socket_dir=socket_dir).run()48 def run_client():49 client = Client(socket_dir=socket_dir, retry_timeout=0.1)50 response = client.call('mock_server', 'mock_method')51 if response['success']:52 rpc_event.set()53 multiprocessing.Process(target=run_server, daemon=True).start()54 multiprocessing.Process(target=run_client, daemon=True).start()55 assert crash_event.wait(1)56 multiprocessing.Process(target=run_server, daemon=True).start()57 # Wait 5 seconds for retry58 assert rpc_event.wait(5)59def test_reliability_server(socket_dir):60 """61 Test server reliability on client crash.62 """63 rpc_event = multiprocessing.Event()64 server_recv_event = multiprocessing.Event()65 client_crash_event = multiprocessing.Event()66 def run_server():67 class MockServer(Server):68 @rpc_method69 def mock_method(self):70 server_recv_event.set()71 client_crash_event.wait()72 return {'success': True}73 MockServer(socket_dir=socket_dir).run()74 def run_client():75 client = Client(socket_dir=socket_dir)76 response = client.call('mock_server', 'mock_method')77 if response['success']:78 rpc_event.set()79 multiprocessing.Process(target=run_server, daemon=True).start()80 client_process = multiprocessing.Process(target=run_client, daemon=True)81 client_process.start()82 assert server_recv_event.wait(1)83 client_process.kill()84 client_process.join()85 client_crash_event.set()86 multiprocessing.Process(target=run_client, daemon=True).start()87 # Wait 5 seconds for retry88 assert rpc_event.wait(5)89def test_args_kwargs(socket_dir):90 """91 Test proper handling of arguments and keyword arguments.92 """93 rpc_event = multiprocessing.Event()94 def run_server():95 class MockServer(Server):96 @rpc_method97 def mock_method(self, arg1, arg2, kwarg1=None, kwarg2=None):98 if (arg1, arg2, kwarg1, kwarg2) == ('1', '2', 3, 4):99 return {'success': True}100 else:101 return {'success': False}102 MockServer(socket_dir=socket_dir).run()103 def run_client():104 client = Client(socket_dir=socket_dir)105 response = client.call(server='mock_server',106 method='mock_method',107 args=('1', '2'),108 kwargs={'kwarg1': 3, 'kwarg2': 4})109 if response['success']:110 rpc_event.set()111 multiprocessing.Process(target=run_server, daemon=True).start()112 multiprocessing.Process(target=run_client, daemon=True).start()113 assert rpc_event.wait(5)114def test_multiprocessing(socket_dir):115 """116 Test whether ZRPC works in multiprocessing environment.117 """118 rpc_event = multiprocessing.Event()119 class MockServer(Server):120 @rpc_method121 def mock_method(self):122 return {'success': True}123 def run_server():124 MockServer(socket_dir=socket_dir).run()125 def run_client():126 mock_client = Client(socket_dir=socket_dir)127 response = mock_client.call('mock_server', 'mock_method')128 if response['success']:129 rpc_event.set()130 multiprocessing.Process(target=run_server, daemon=True).start()131 multiprocessing.Process(target=run_client, daemon=True).start()132 assert rpc_event.wait(1)133def test_client_timeout(socket_dir):134 """135 Test whether client raises RPCTimeoutError on `call()` timeout.136 """137 client_event = multiprocessing.Event()138 def run_client():139 client = Client(socket_dir=socket_dir)140 try:141 client.call('non_existant', 'non_existant', timeout=0.1)142 except RPCTimeoutError:143 client_event.set()144 multiprocessing.Process(target=run_client, daemon=True).start()145 assert client_event.wait(1)146def test_server_restart(socket_dir):147 """148 Test whether server works properly on restart.149 """150 number_of_restarts = 5151 def run_server_n_times(n):152 class MockServer(Server):153 @rpc_method154 def mock_method(self):155 return {'success': True}156 server = MockServer(socket_dir=socket_dir)157 for i in range(n):158 with server:159 server.run_once()160 multiprocessing.Process(target=run_server_n_times,161 args=[number_of_restarts],162 daemon=True).start()163 for i in range(number_of_restarts):164 client = Client(socket_dir=socket_dir)165 response = client.call('mock_server', 'mock_method', timeout=3)166 assert response['success']167def test_server_cache(socket_dir):168 counter = multiprocessing.Value('i')169 counter.value = 0170 class MockServer(Server):171 @rpc_method172 def mock_method(self):173 time.sleep(0.1)174 counter.value += 1175 return {'success': True}176 def run_server():177 MockServer(socket_dir=socket_dir).run()178 multiprocessing.Process(target=run_server, daemon=True).start()179 # Retry 10 times180 client = Client(socket_dir=socket_dir, retry_timeout=0.01)181 client.call(server='mock_server', method='mock_method', timeout=1)182 # Assert method executed only once183 assert counter.value == 1184def test_server_stop(socket_dir):185 event = multiprocessing.Event()186 class MockServer(Server):187 @rpc_method188 def mock_method(self):189 pass190 def __exit__(self, *args, **kwargs):191 super().__exit__(*args, **kwargs)192 event.set()193 def run_server():194 MockServer(socket_dir=socket_dir).run()195 p = multiprocessing.Process(target=run_server, daemon=True)196 p.start()197 client = Client(socket_dir=socket_dir)198 client.call(server='mock_server', method='mock_method', timeout=1)199 os.kill(p.pid, 2)200 p.join(timeout=1)201 assert event.is_set()202def test_server_register(socket_dir):203 queue = multiprocessing.Queue()204 recv_event = multiprocessing.Event()205 def run_server():206 class TestServer(Server):207 def run(self):208 self.register(queue._reader.fileno(), self.queue_event)209 super().run()210 def queue_event(self):211 assert queue.get() == 'foo'212 recv_event.set()213 TestServer().run()214 p = multiprocessing.Process(target=run_server)215 p.start()216 queue.put('foo')217 assert recv_event.wait(1)218 p.terminate()219 p.join()

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...19 contains_string('Usage: ./{} <port>'.format(fname)))20class UDPTests(TestCase):21 def setUp(self):22 context.port = 200023 def run_server(self, prog):24 server = Task(detach=True)25 server.assert_that(localhost,26 is_not(listen_port(context.port, proto='udp')))27 server.command('./{0} $port'.format(prog), timeout=15, expected=None)28 clients = self.run_clients()29 wait_clients(clients)30 def run_clients(self):31 Task().wait_that(localhost, listen_port(context.port, proto='udp'))32 clients = []33 for i in range(10):34 req = 'hello-%s' % i35 client = Task(detach=True)36 client.command('echo %s | ./UDP_client.py localhost $port' % req,37 timeout=15)38 client.assert_that(client.lastcmd.stdout.content,39 contains_string("Reply is '" + req.upper()))40 clients.append(client)41 return clients42 def test_basic(self):43 self.run_server('UDP_server.py')44 def test_fork(self):45 self.run_server('UDP_fork.py')46 def test_SocketServer(self):47 self.run_server('UDP_SS.py')48 def test_SocketServer_fork(self):49 self.run_server('UDP_SS_fork.py')50class TCPTests(TestCase):51 def setUp(self):52 context.port = 200053 context.timeout = 2054 def run_server(self, prog):55 server = Task('server', detach=True)56 server.assert_that(localhost,57 is_not(listen_port(context.port, proto='tcp')))58 server.command("./{0} $port".format(prog), expected=None)59 clients = self.run_clients()60 wait_clients(clients)61 def run_clients(self):62 Task().wait_that(localhost, listen_port(context.port, proto='tcp'))63 clients = []64 for i in range(10):65 req = 'hello-%s' % i66 client = Task('client', detach=True)67 client.command('echo %s | ./TCP_client.py localhost $port' % req)68 client.assert_that(client.lastcmd.stdout.content,69 contains_string("Reply is '" + req.upper()))70 clients.append(client)71 return clients72 def test_basic(self):73 self.run_server('TCP_server.py')74 def test_SocketServer(self):75 self.run_server('TCP_SS.py')76 def test_fork(self):77 self.run_server('TCP_fork.py')78 def test_SocketServer_fork(self):79 self.run_server('TCP_SS_fork.py')80 def test_process(self):81 self.run_server('TCP_process.py')82 def test_workers(self):83 self.run_server('TCP_workers.py')84 def test_thread(self):85 self.run_server('TCP_thread.py')86 def test_SocketServer_thread(self):87 self.run_server('TCP_SS_thread.py')88 def test_select(self):89 self.run_server('TCP_select.py')90 def test_asyncore(self):91 self.run_server('TCP_asyncore.py')92# def test_twisted(self):93# self.run_server('TCP_twisted.py')94class TCP6Tests(TestCase):95 def setUp(self):96 context.port = 200097 context.timeout = 4098 def run_server(self, prog):99 server = Task('server', detach=True)100 server.assert_that(localhost,101 is_not(listen_port(context.port, proto='tcp')))102 server.command("./{0} $port".format(prog), expected=None)103 def run_clients(self, prog):104 Task().wait_that(localhost, listen_port(context.port, proto='tcp'))105 clients = []106 for i in range(10):107 req = 'hello-%s' % i108 client = Task('client', detach=True)109 client.command('echo {0} | ./{1} $port'.format(req, prog))110 client.assert_that(client.lastcmd.stdout.content,111 contains_string("Reply is '" + req.upper()))112 clients.append(client)113 return clients114 def test_basic_with_ipv4_client(self):115 self.run_server('TCP6_server.py')116 clients = self.run_clients('TCP_client.py 127.0.0.1')117 wait_clients(clients)118 def test_basic_with_ipv6_client(self):119 self.run_server('TCP6_server.py')120 clients = self.run_clients('TCP6_client.py ::1')...

Full Screen

Full Screen

run_python.py

Source:run_python.py Github

copy

Full Screen

1#!/usr/bin/env python2from util import pushd, run_server, run, example_root3with pushd(example_root):4 with pushd('shogun'):5 with run_server('jubaclassifier', '-f', 'shogun.json'):6 with pushd('python'):7 run('python', 'shogun.py')8 with pushd('gender'):9 with run_server('jubaclassifier', '-f', 'gender.json'):10 with pushd('python'):11 run('python', 'gender.py')12 with pushd('twitter_streaming_lang'):13 with run_server('jubaclassifier', '-f', 'twitter_streaming_lang.json'):14 pass15 with pushd('twitter_streaming_location'):16 with run_server('jubaclassifier', '-f', 'twitter_streaming_location.json'):17 pass18 with pushd('movielens'):19 with run_server('jubarecommender', '-f', 'config.json'):20 with pushd('python'):21 run('python', 'ml_update.py')22 run('python', 'ml_analysis.py')23 with pushd('npb_similar_player'):24 with run_server('jubarecommender', '-f', 'npb_similar_player.json'):25 with pushd('python'):26 run('python', 'update.py')27 run('python', 'analyze.py')28 with pushd('rent'):29 with run_server('jubaregression', '-f', 'rent.json'):30 with pushd('python'):31 run('python', 'jubahomes.py',32 '-t', '../dat/rent-data.csv',33 '-a', '../dat/myhome.yml')34 with pushd('train_route'):35 with run_server('jubagraph', '-f', 'train_route.json'):36 with pushd('python'):37 run('python', 'create_graph.py')38 run('python', 'search_route.py', '0', '144')39 with pushd('language_detection'):40 with run_server('jubaclassifier', '-f', 'space_split.json'):41 with pushd('python'):42 run('python', 'train.py')43 run('python', 'test.py', input='this is a pen\n\n')44 with pushd('trivial_stat'):45 with run_server('jubastat', '-f', 'stat.json'):46 with pushd('python'):...

Full Screen

Full Screen

run_ruby.py

Source:run_ruby.py Github

copy

Full Screen

1#!/usr/bin/env python2from util import pushd, run_server, run, example_root3with pushd(example_root):4 with pushd('shogun'):5 with run_server('jubaclassifier', '-f', 'shogun.json'):6 with pushd('ruby'):7 run('ruby', 'shogun.rb')8 with pushd('gender'):9 with run_server('jubaclassifier', '-f', 'gender.json'):10 with pushd('ruby'):11 run('ruby', 'gender.rb')12 with pushd('movielens'):13 with run_server('jubarecommender', '-f', 'config.json'):14 with pushd('ruby'):15 run('ruby', 'ml_update.rb')16 run('ruby', 'ml_analysis.rb')17 with pushd('npb_similar_player'):18 with run_server('jubarecommender', '-f', 'npb_similar_player.json'):19 with pushd('ruby'):20 run('ruby', 'update.rb')21 run('ruby', 'analyze.rb')22 with pushd('rent'):23 with run_server('jubaregression', '-f', 'rent.json'):24 with pushd('ruby'):25 run('ruby', 'train.rb', '../dat/rent-data.csv')26 run('ruby', 'test.rb', input='19.9\n2\n22\n4\nW\n')27 with pushd('language_detection'):28 with run_server('jubaclassifier', '-f', 'space_split.json'):29 with pushd('ruby'):30 run('ruby', 'train.rb')31 run('ruby', 'test.rb', input='this is a pen\n\n')32 with pushd('winequality'):33 with run_server('jubaregression', '-f', 'config.json'):34 with pushd('ruby'):35 run('ruby', 'train.rb')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful