From 1e8ceea9a8d6fb14f8ac8a88294f26a23471469c Mon Sep 17 00:00:00 2001 From: Lukas Phaf Date: Fri, 8 Sep 2023 14:07:01 +0200 Subject: [PATCH] Check for correct response. --- .github/workflows/ci.yml | 1 + examples/clients/python/client.py | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e3c06c..2bda9be 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,4 +24,5 @@ jobs: run: docker compose up --exit-code-from loader - name: Cleanup + if: always() run: docker compose down --volumes diff --git a/examples/clients/python/client.py b/examples/clients/python/client.py index e1a96ed..14bd73b 100755 --- a/examples/clients/python/client.py +++ b/examples/clients/python/client.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 # tested with Python 3.11 +# Generate protobuf code with following command from top level directory: +# python -m grpc_tools.protoc --proto_path=datastore/protobuf datastore.proto --python_out=examples/clients/python --grpc_python_out=examples/clients/python import os from datetime import datetime @@ -9,6 +11,8 @@ import datastore_pb2_grpc as dstore_grpc import grpc +MAGIC_ID = 1234567890 +MAGIC_VALUE = 123.456 def callAddTimeSeries(stub): print('calling AddTimeSeries() ...') @@ -24,7 +28,7 @@ def callAddTimeSeries(stub): other3='value3', ) request = dstore.AddTSRequest( - id=1234567890, + id=MAGIC_ID, metadata=tsMData, ) response = stub.AddTimeSeries(request) @@ -42,14 +46,14 @@ def callPutObservations(stub): obs = [ dstore.Observation( time=timestamp, - value=123.456, + value=MAGIC_VALUE, metadata=obsMData, ) ] request = dstore.PutObsRequest( tsobs=[ dstore.TSObservations( - tsid=1234567890, + tsid=MAGIC_ID, obs=obs, ) ], @@ -73,13 +77,23 @@ def callGetObservations(stub): response = stub.GetObservations(request) print(' response: {}'.format(response)) + return response + if __name__ == '__main__': with grpc.insecure_channel(f"{os.getenv('DSHOST', 'localhost')}:{os.getenv('DSPORT', '50050')}") as channel: stub = dstore_grpc.DatastoreStub(channel) - callAddTimeSeries(stub) callAddTimeSeries(stub) callPutObservations(stub) - callGetObservations(stub) + response = callGetObservations(stub) + + # Check response + found_at_least_one = False + for r in response.tsobs: + if r.tsid == MAGIC_ID: + for o in r.obs: + assert(o.value == MAGIC_VALUE) + found_at_least_one = True + assert found_at_least_one