Skip to content

Commit

Permalink
Make test pass with fake ring rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
pelletier committed Jan 28, 2024
1 parent 6fa5745 commit 1051606
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions tests/test_ring.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
import unittest
import concurrent.futures.thread

import dispatch
import ring.task.v1.service_pb2
import ring.task.v1.service_pb2 as service_pb
import ring.task.v1.service_pb2_grpc as service_grpc
import dispatch.http.v1.http_pb2
import grpc
import google.protobuf.any_pb2


class FakeRing(service_grpc.ServiceServicer):
def CreateTasks(self, request, context):
return service_pb.CreateTasksResponse()


class TestRing(unittest.TestCase):
def setUp(self):
self.thread_pool = concurrent.futures.thread.ThreadPoolExecutor()
self.server = grpc.server(self.thread_pool)

port = self.server.add_insecure_port("127.0.0.1:0")

servicer = FakeRing()

service_grpc.add_ServiceServicer_to_server(servicer, self.server)
self.server.start()

channel = grpc.insecure_channel(f"127.0.0.1:{port}")
self.ring_stub = service_grpc.ServiceStub(channel)

def tearDown(self):
self.server.stop(0)
self.server.wait_for_termination()
self.thread_pool.shutdown(wait=True, cancel_futures=True)

def test_ring(self):
channel = grpc.insecure_channel("localhost:4001")
stub = ring.task.v1.service_pb2_grpc.ServiceStub(channel)

request = dispatch.http.v1.http_pb2.Request(
url="https://www.google.com", method="GET"
Expand All @@ -19,9 +43,9 @@ def test_ring(self):
input = google.protobuf.any_pb2.Any()
input.Pack(request)

create_task_input = ring.task.v1.service_pb2.CreateTaskInput(
create_task_input = service_pb.CreateTaskInput(
coroutine_uri="arn:aws:lambda:us-west-2:012345678912:function:dispatch-http",
input=input,
)
req = ring.task.v1.service_pb2.CreateTasksRequest(tasks=[create_task_input])
resp = stub.CreateTasks(req)
req = service_pb.CreateTasksRequest(tasks=[create_task_input])
resp = self.ring_stub.CreateTasks(req)

0 comments on commit 1051606

Please sign in to comment.