11# (C) 2024 GoodData Corporation
22import orjson
33import pyarrow .flight
4+ import pytest
5+ from gooddata_flight_server import ErrorCode
46
7+ from tests .assert_error_info import assert_error_code
58from tests .server .conftest import flexconnect_server
69
710
@@ -16,12 +19,12 @@ def test_basic_function():
1619 assert fun_info .descriptor .command is not None
1720 assert len (fun_info .descriptor .command )
1821 cmd = orjson .loads (fun_info .descriptor .command )
19- assert cmd ["functionName" ] == "SimpleFun "
22+ assert cmd ["functionName" ] == "SimpleFun1 "
2023
2124 descriptor = pyarrow .flight .FlightDescriptor .for_command (
2225 orjson .dumps (
2326 {
24- "functionName" : "SimpleFun " ,
27+ "functionName" : "SimpleFun1 " ,
2528 "parameters" : {"test1" : 1 , "test2" : 2 , "test3" : 3 },
2629 }
2730 )
@@ -45,7 +48,7 @@ def test_function_with_on_load():
4548 descriptor = pyarrow .flight .FlightDescriptor .for_command (
4649 orjson .dumps (
4750 {
48- "functionName" : "SimpleFun " ,
51+ "functionName" : "SimpleFun2 " ,
4952 "parameters" : {"test1" : 1 , "test2" : 2 , "test3" : 3 },
5053 }
5154 )
@@ -69,12 +72,12 @@ def test_basic_function_tls(tls_ca_cert):
6972 assert fun_info .descriptor .command is not None
7073 assert len (fun_info .descriptor .command )
7174 cmd = orjson .loads (fun_info .descriptor .command )
72- assert cmd ["functionName" ] == "SimpleFun "
75+ assert cmd ["functionName" ] == "SimpleFun1 "
7376
7477 descriptor = pyarrow .flight .FlightDescriptor .for_command (
7578 orjson .dumps (
7679 {
77- "functionName" : "SimpleFun " ,
80+ "functionName" : "SimpleFun1 " ,
7881 "parameters" : {"test1" : 1 , "test2" : 2 , "test3" : 3 },
7982 }
8083 )
@@ -84,3 +87,32 @@ def test_basic_function_tls(tls_ca_cert):
8487
8588 assert len (data ) == 3
8689 assert data .column_names == ["col1" , "col2" , "col3" ]
90+
91+
92+ def test_function_with_call_deadline ():
93+ """
94+ Flight RPC implementation that invokes FlexConnect can be setup with
95+ deadline for the invocation duration (done by GetFlightInfo).
96+
97+ If the function invocation (or wait for the invocation) exceeds the
98+ deadline, the GetFlightInfo will fail with timeout and the underlying
99+ task will be cancelled (if possible).
100+
101+ In these cases, the GetFlightInfo raises FlightTimedOutError with
102+ appropriate error code.
103+ """
104+ with flexconnect_server (["tests.server.funs.fun3" ]) as s :
105+ c = pyarrow .flight .FlightClient (s .location )
106+ descriptor = pyarrow .flight .FlightDescriptor .for_command (
107+ orjson .dumps (
108+ {
109+ "functionName" : "LongRunningFun" ,
110+ "parameters" : {"test1" : 1 , "test2" : 2 , "test3" : 3 },
111+ }
112+ )
113+ )
114+
115+ with pytest .raises (pyarrow .flight .FlightTimedOutError ) as e :
116+ c .get_flight_info (descriptor )
117+
118+ assert_error_code (ErrorCode .TIMEOUT , e .value )
0 commit comments