Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bank/backend/src/account_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
WithdrawResponse,
)
from bank.v1.errors_pb2 import OverdraftError
from reboot.aio.auth.authorizers import allow
from reboot.aio.contexts import ReaderContext, WriterContext

logging.basicConfig(level=logging.INFO)


class AccountServicer(Account.Servicer):

def authorizer(self):
return allow()

async def Open(
self,
context: WriterContext,
Expand Down
4 changes: 4 additions & 0 deletions bank/backend/src/bank_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
TransferRequest,
TransferResponse,
)
from reboot.aio.auth.authorizers import allow
from reboot.aio.contexts import TransactionContext

logging.basicConfig(level=logging.INFO)


class BankServicer(Bank.Servicer):

def authorizer(self):
return allow()

async def SignUp(
self,
context: TransactionContext,
Expand Down
5 changes: 3 additions & 2 deletions bank/backend/tests/account_servicer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from account_servicer import AccountServicer
from bank.v1.account_rbt import Account, BalanceResponse
from bank.v1.errors_pb2 import OverdraftError
from reboot.aio.applications import Application
from reboot.aio.tests import Reboot
from unittest import mock

Expand All @@ -23,7 +24,7 @@ async def asyncTearDown(self) -> None:
async def test_basics(self) -> None:
context = self.rbt.create_external_context(name=f"test-{self.id()}")

await self.rbt.up(servicers=[AccountServicer])
await self.rbt.up(Application(servicers=[AccountServicer]))

# Create the state machine by calling its constructor. The fact that the
# state machine _has_ a constructor means that this step is required
Expand Down Expand Up @@ -72,7 +73,7 @@ async def withdraw():
@mock.patch("account_servicer.send_email")
async def test_send_welcome_email(self, mock_send_email) -> None:
await self.rbt.up(
servicers=[AccountServicer],
Application(servicers=[AccountServicer]),
# Normally, `rbt.up()` runs the servicers in a separate process, to
# ensure that accidental use of blocking functions (an easy mistake
# to make) don't cause the test to lock up. However, in this test
Expand Down
9 changes: 7 additions & 2 deletions bank/backend/tests/bank_servicer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from bank.v1.bank_rbt import Bank, SignUpResponse
from bank.v1.errors_pb2 import OverdraftError
from bank_servicer import BankServicer
from reboot.aio.applications import Application
from reboot.aio.tests import Reboot


Expand All @@ -17,7 +18,9 @@ async def asyncTearDown(self) -> None:
await self.rbt.stop()

async def test_signup(self) -> None:
await self.rbt.up(servicers=[BankServicer, AccountServicer])
await self.rbt.up(
Application(servicers=[BankServicer, AccountServicer])
)
context = self.rbt.create_external_context(name=f"test-{self.id()}")
bank = Bank.ref("my-bank")

Expand All @@ -34,7 +37,9 @@ async def test_signup(self) -> None:
self.assertEqual(response.balance, 0)

async def test_transfer(self):
await self.rbt.up(servicers=[BankServicer, AccountServicer])
await self.rbt.up(
Application(servicers=[BankServicer, AccountServicer])
)
context = self.rbt.create_external_context(name=f"test-{self.id()}")
bank = Bank.ref("my-bank")

Expand Down
4 changes: 4 additions & 0 deletions hello-constructors/backend/src/hello_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
SendRequest,
SendResponse,
)
from reboot.aio.auth.authorizers import allow
from reboot.aio.contexts import ReaderContext, WriterContext


class HelloServicer(Hello.Servicer):

def authorizer(self):
return allow()

async def Create(
self,
context: WriterContext,
Expand Down
3 changes: 2 additions & 1 deletion hello-constructors/backend/tests/hello_servicer_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from hello_constructors.v1.hello_rbt import Hello
from hello_servicer import HelloServicer
from reboot.aio.applications import Application
from reboot.aio.tests import Reboot


Expand All @@ -14,7 +15,7 @@ async def asyncTearDown(self) -> None:
await self.rbt.stop()

async def test_hello_constructors(self) -> None:
await self.rbt.up(servicers=[HelloServicer])
await self.rbt.up(Application(servicers=[HelloServicer]))

context = self.rbt.create_external_context(name=f"test-{self.id()}")

Expand Down
4 changes: 4 additions & 0 deletions hello-legacy-grpc/backend/src/deprecated_greeter_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
import random
from google.protobuf.empty_pb2 import Empty
from hello_legacy_grpc.v1 import greeter_pb2, greeter_pb2_grpc
from reboot.aio.auth.authorizers import allow


class DeprecatedGreeterServicer(greeter_pb2_grpc.DeprecatedGreeterServicer):

def authorizer(self):
return allow()

async def Greet(
self,
request: greeter_pb2.GreetRequest,
Expand Down
4 changes: 3 additions & 1 deletion hello-legacy-grpc/backend/src/proxy_greeter_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ async def Greet(
# new Reboot service. This proxy servicer will forward traffic to
# either the RebootGreeter or the DeprecatedGreeter with a 50/50
# ratio.
context = legacy_context.external_context(name=self.Greet.__name__)
context = legacy_context.external_context(
name="Call into `RebootGreeter`"
)
if random.random() < 0.5:
# Route to RebootGreeter.
reboot_greeter = RebootGreeter.ref("my-greeter")
Expand Down
4 changes: 4 additions & 0 deletions hello-legacy-grpc/backend/src/reboot_greeter_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
GreetResponse,
RebootGreeter,
)
from reboot.aio.auth.authorizers import allow
from reboot.aio.contexts import (
Context,
ReaderContext,
Expand All @@ -20,6 +21,9 @@

class RebootGreeterServicer(RebootGreeter.Servicer):

def authorizer(self):
return allow()

async def _get_deprecated_salutation(self, context: Context) -> str:
"""Fetch a salutation from the deprecated Greeter service written in
legacy gRPC."""
Expand Down
22 changes: 15 additions & 7 deletions hello-legacy-grpc/backend/tests/greeter_servicer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from hello_legacy_grpc.v1 import greeter_pb2, greeter_pb2_grpc
from hello_legacy_grpc.v1.greeter_rbt import RebootGreeter
from proxy_greeter_servicer import ProxyGreeterServicer
from reboot.aio.applications import Application
from reboot.aio.tests import Reboot
from reboot_greeter_servicer import RebootGreeterServicer

Expand All @@ -19,8 +20,10 @@ async def asyncTearDown(self) -> None:

async def test_reboot_greeter(self) -> None:
await self.rbt.up(
servicers=[RebootGreeterServicer],
legacy_grpc_servicers=[DeprecatedGreeterServicer],
Application(
servicers=[RebootGreeterServicer],
legacy_grpc_servicers=[DeprecatedGreeterServicer],
),
)

context = self.rbt.create_external_context(name=f"test-{self.id()}")
Expand All @@ -46,7 +49,9 @@ async def test_reboot_greeter(self) -> None:
)

async def test_deprecated_greeter(self) -> None:
await self.rbt.up(legacy_grpc_servicers=[DeprecatedGreeterServicer])
await self.rbt.up(
Application(legacy_grpc_servicers=[DeprecatedGreeterServicer])
)

context = self.rbt.create_external_context(name=f"test-{self.id()}")

Expand All @@ -66,10 +71,13 @@ async def test_deprecated_greeter(self) -> None:
)
async def test_proxy_greeter(self) -> None:
await self.rbt.up(
servicers=[RebootGreeterServicer],
legacy_grpc_servicers=[
DeprecatedGreeterServicer, ProxyGreeterServicer
],
Application(
servicers=[RebootGreeterServicer],
legacy_grpc_servicers=[
DeprecatedGreeterServicer,
ProxyGreeterServicer,
],
),
local_envoy=True,
)

Expand Down
4 changes: 4 additions & 0 deletions hello-tasks/backend/src/hello_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
WarningRequest,
WarningResponse,
)
from reboot.aio.auth.authorizers import allow
from reboot.aio.contexts import ReaderContext, WriterContext

SECS_UNTIL_WARNING = 7
Expand All @@ -20,6 +21,9 @@

class HelloServicer(Hello.Servicer):

def authorizer(self):
return allow()

async def Messages(
self,
context: ReaderContext,
Expand Down
3 changes: 2 additions & 1 deletion hello-tasks/backend/tests/hello_servicer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import unittest
from hello_servicer import HelloServicer
from hello_tasks.v1.hello_rbt import Hello
from reboot.aio.applications import Application
from reboot.aio.tests import Reboot


Expand All @@ -20,7 +21,7 @@ async def test_hello_tasks(self) -> None:
hello_servicer.SECS_UNTIL_WARNING = 0
hello_servicer.ADDITIONAL_SECS_UNTIL_ERASE = 0
await self.rbt.up(
servicers=[HelloServicer],
Application(servicers=[HelloServicer]),
# Normally, `rbt.up()` runs the servicers in a separate process, to
# ensure that accidental use of blocking functions (an easy mistake
# to make) doesn't cause the test to lock up. However, in this test
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[project]
requires-python = ">= 3.10"
dependencies = [
"reboot==0.24.0",
"reboot==0.25.1",
]

[tool.rye]
dev-dependencies = [
"mypy==1.2.0",
"pytest>=7.4.2",
"types-protobuf>=4.24.0.20240129",
"reboot==0.24.0",
"reboot==0.25.1",
]

# This project only uses `rye` to provide `python` and its dependencies, so
Expand Down
29 changes: 28 additions & 1 deletion requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ aiohttp==3.10.5
# via reboot
aiosignal==1.3.1
# via aiohttp
annotated-types==0.7.0
# via pydantic
anyio==4.9.0
# via starlette
async-timeout==4.0.3
# via aiohttp
attrs==24.2.0
Expand All @@ -25,6 +29,8 @@ certifi==2024.8.30
cffi==1.17.1
# via cryptography
# via reboot
click==8.1.8
# via uvicorn
colorama==0.4.6
# via reboot
cryptography==44.0.0
Expand All @@ -34,7 +40,10 @@ deprecated==1.2.15
# via opentelemetry-exporter-otlp-proto-grpc
# via opentelemetry-semantic-conventions
exceptiongroup==1.2.2
# via anyio
# via pytest
fastapi==0.115.12
# via reboot
frozenlist==1.4.1
# via aiohttp
# via aiosignal
Expand All @@ -60,7 +69,10 @@ grpcio-status==1.64.3
# via reboot
grpcio-tools==1.64.3
# via reboot
h11==0.14.0
# via uvicorn
idna==3.10
# via anyio
# via yarl
importlib-metadata==8.5.0
# via opentelemetry-api
Expand Down Expand Up @@ -129,6 +141,10 @@ psutil==6.0.0
# via reboot
pycparser==2.22
# via cffi
pydantic==2.9.2
# via fastapi
pydantic-core==2.23.4
# via pydantic
pyjwt==2.8.0
# via reboot
pyprctl==0.1.3
Expand All @@ -139,14 +155,18 @@ python-dateutil==2.9.0.post0
pyyaml==6.0.2
# via kubernetes-asyncio
# via reboot
reboot==0.24.0
reboot==0.25.1
setuptools==75.1.0
# via grpcio-tools
six==1.16.0
# via kubernetes-asyncio
# via python-dateutil
sniffio==1.3.1
# via anyio
sortedcontainers==2.4.0
# via reboot
starlette==0.46.2
# via fastapi
tabulate==0.9.0
# via reboot
tomli==2.0.1
Expand All @@ -155,17 +175,24 @@ tomli==2.0.1
types-protobuf==5.28.0.20240924
# via mypy-protobuf
typing-extensions==4.9.0
# via anyio
# via fastapi
# via multidict
# via mypy
# via opentelemetry-sdk
# via pydantic
# via pydantic-core
# via reboot
# via uvicorn
tzlocal==5.3
# via reboot
urllib3==1.26.15
# via kubernetes-asyncio
# via reboot
uuid7==0.1.0
# via reboot
uvicorn==0.34.0
# via reboot
watchdog==6.0.0
# via reboot
websockets==13.1
Expand Down
Loading