|
| 1 | +# Copyright 2022 CodeNotary, Inc. All rights reserved. |
| 2 | + |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | +# See the License for the specific language governing permissions and |
| 11 | +# limitations under the License. |
| 12 | + |
| 13 | +from immudb.client import ImmudbClient |
| 14 | +import pytest |
| 15 | +from grpc import RpcError, StatusCode |
| 16 | +import uuid |
| 17 | + |
| 18 | +def generateBigDict(): |
| 19 | + toBuild = dict() |
| 20 | + keyList = [] |
| 21 | + for _ in range(0, 128): |
| 22 | + bigStr = str(uuid.uuid4()) * 512 |
| 23 | + key = str(uuid.uuid4()).encode("utf-8") |
| 24 | + keyList.append(key) |
| 25 | + toBuild[key] = bigStr.encode("utf-8") |
| 26 | + return toBuild, keyList |
| 27 | + |
| 28 | + |
| 29 | +class TestTimeout: |
| 30 | + def test_simple_timeout(self, argsToBuildClient): |
| 31 | + url, login, password = argsToBuildClient |
| 32 | + client = ImmudbClient(url, timeout=1) |
| 33 | + client.login(login, password) |
| 34 | + |
| 35 | + with pytest.raises(RpcError) as excinfo: |
| 36 | + client = ImmudbClient(url, timeout=0.001) |
| 37 | + client.login(login, password) |
| 38 | + assert excinfo.value.code() == StatusCode.DEADLINE_EXCEEDED |
| 39 | + |
| 40 | + |
| 41 | + with pytest.raises(RpcError) as excinfo: |
| 42 | + client = ImmudbClient(url, timeout=0.05) |
| 43 | + client.login(login, password) |
| 44 | + keyVal, keys = generateBigDict() |
| 45 | + client.setAll(keyVal) |
| 46 | + scanned = client.scan(b"", b"", False, 400) |
| 47 | + assert excinfo.value.code() == StatusCode.DEADLINE_EXCEEDED |
| 48 | + |
0 commit comments