@@ -95,7 +95,7 @@ func TestConn_executeStatement(t *testing.T) {
95
95
},
96
96
OperationHandle : & cli_service.TOperationHandle {
97
97
OperationId : & cli_service.THandleIdentifier {
98
- GUID : []byte {1 , 2 , 3 , 4 , 2 , 23 , 4 , 2 , 3 , 1 , 2 , 3 , 4 , 4 , 223 , 34 , 54 },
98
+ GUID : []byte {1 , 2 , 3 , 4 , 2 , 23 , 4 , 2 , 3 , 1 , 2 , 3 , 4 , 223 , 34 , 54 },
99
99
Secret : []byte ("b" ),
100
100
},
101
101
},
@@ -344,7 +344,7 @@ func TestConn_pollOperation(t *testing.T) {
344
344
}
345
345
res , err := testConn .pollOperation (context .Background (), & cli_service.TOperationHandle {
346
346
OperationId : & cli_service.THandleIdentifier {
347
- GUID : []byte {1 , 2 , 3 , 4 , 2 , 23 , 4 , 2 , 3 , 2 , 3 , 4 , 4 , 223 , 34 , 54 },
347
+ GUID : []byte {1 , 2 , 3 , 4 , 2 , 23 , 4 , 2 , 3 , 2 , 4 , 7 , 8 , 223 , 34 , 54 },
348
348
Secret : []byte ("b" ),
349
349
},
350
350
})
@@ -1059,6 +1059,11 @@ func TestConn_ExecContext(t *testing.T) {
1059
1059
1060
1060
testClient := & client.TestClient {
1061
1061
FnExecuteStatement : executeStatement ,
1062
+ FnCloseOperation : func (ctx context.Context , req * cli_service.TCloseOperationReq ) (_r * cli_service.TCloseOperationResp , _err error ) {
1063
+ ctxErr := ctx .Err ()
1064
+ assert .NoError (t , ctxErr )
1065
+ return & cli_service.TCloseOperationResp {}, nil
1066
+ },
1062
1067
}
1063
1068
testConn := & conn {
1064
1069
session : getTestSession (),
@@ -1102,6 +1107,11 @@ func TestConn_ExecContext(t *testing.T) {
1102
1107
testClient := & client.TestClient {
1103
1108
FnExecuteStatement : executeStatement ,
1104
1109
FnGetOperationStatus : getOperationStatus ,
1110
+ FnCloseOperation : func (ctx context.Context , req * cli_service.TCloseOperationReq ) (_r * cli_service.TCloseOperationResp , _err error ) {
1111
+ ctxErr := ctx .Err ()
1112
+ assert .NoError (t , ctxErr )
1113
+ return & cli_service.TCloseOperationResp {}, nil
1114
+ },
1105
1115
}
1106
1116
testConn := & conn {
1107
1117
session : getTestSession (),
@@ -1116,6 +1126,71 @@ func TestConn_ExecContext(t *testing.T) {
1116
1126
assert .Equal (t , int64 (10 ), rowsAffected )
1117
1127
assert .Equal (t , 1 , executeStatementCount )
1118
1128
})
1129
+ t .Run ("ExecContext uses new context to close operation" , func (t * testing.T ) {
1130
+ var executeStatementCount , getOperationStatusCount , closeOperationCount , cancelOperationCount int
1131
+ var cancel context.CancelFunc
1132
+ executeStatement := func (ctx context.Context , req * cli_service.TExecuteStatementReq ) (r * cli_service.TExecuteStatementResp , err error ) {
1133
+ executeStatementCount ++
1134
+ executeStatementResp := & cli_service.TExecuteStatementResp {
1135
+ Status : & cli_service.TStatus {
1136
+ StatusCode : cli_service .TStatusCode_SUCCESS_STATUS ,
1137
+ },
1138
+ OperationHandle : & cli_service.TOperationHandle {
1139
+ OperationId : & cli_service.THandleIdentifier {
1140
+ GUID : []byte {1 , 2 , 3 , 4 , 2 , 23 , 4 , 2 , 3 , 2 , 3 , 4 , 4 , 223 , 34 , 54 },
1141
+ Secret : []byte ("b" ),
1142
+ },
1143
+ },
1144
+ }
1145
+ return executeStatementResp , nil
1146
+ }
1147
+
1148
+ getOperationStatus := func (ctx context.Context , req * cli_service.TGetOperationStatusReq ) (r * cli_service.TGetOperationStatusResp , err error ) {
1149
+ getOperationStatusCount ++
1150
+ cancel ()
1151
+ getOperationStatusResp := & cli_service.TGetOperationStatusResp {
1152
+ OperationState : cli_service .TOperationStatePtr (cli_service .TOperationState_FINISHED_STATE ),
1153
+ NumModifiedRows : thrift .Int64Ptr (10 ),
1154
+ }
1155
+ return getOperationStatusResp , nil
1156
+ }
1157
+
1158
+ testClient := & client.TestClient {
1159
+ FnExecuteStatement : executeStatement ,
1160
+ FnGetOperationStatus : getOperationStatus ,
1161
+ FnCloseOperation : func (ctx context.Context , req * cli_service.TCloseOperationReq ) (_r * cli_service.TCloseOperationResp , _err error ) {
1162
+ closeOperationCount ++
1163
+ ctxErr := ctx .Err ()
1164
+ assert .NoError (t , ctxErr )
1165
+ return & cli_service.TCloseOperationResp {}, nil
1166
+ },
1167
+ FnCancelOperation : func (ctx context.Context , req * cli_service.TCancelOperationReq ) (r * cli_service.TCancelOperationResp , err error ) {
1168
+ cancelOperationCount ++
1169
+ cancelOperationResp := & cli_service.TCancelOperationResp {
1170
+ Status : & cli_service.TStatus {
1171
+ StatusCode : cli_service .TStatusCode_SUCCESS_STATUS ,
1172
+ },
1173
+ }
1174
+ return cancelOperationResp , nil
1175
+ },
1176
+ }
1177
+ testConn := & conn {
1178
+ session : getTestSession (),
1179
+ client : testClient ,
1180
+ cfg : config .WithDefaults (),
1181
+ }
1182
+ ctx := context .Background ()
1183
+ ctx , cancel = context .WithCancel (ctx )
1184
+ defer cancel ()
1185
+ res , err := testConn .ExecContext (ctx , "insert 10" , []driver.NamedValue {})
1186
+ time .Sleep (10 * time .Millisecond )
1187
+ assert .Error (t , err )
1188
+ assert .Nil (t , res )
1189
+ assert .Equal (t , 1 , executeStatementCount )
1190
+ assert .Equal (t , 1 , cancelOperationCount )
1191
+ assert .Equal (t , 1 , getOperationStatusCount )
1192
+ assert .Equal (t , 1 , closeOperationCount )
1193
+ })
1119
1194
}
1120
1195
1121
1196
func TestConn_QueryContext (t * testing.T ) {
0 commit comments