@@ -83,8 +83,6 @@ func (suite *QuerySuite) TestBadRequest() {
83
83
`{"query": "select * from repositories", "limit": "string"}` ,
84
84
}
85
85
86
- suite .mock .ExpectQuery (".*" ).WillReturnError (fmt .Errorf ("forced err" ))
87
-
88
86
for _ , tc := range testCases {
89
87
suite .T ().Run (tc , func (t * testing.T ) {
90
88
a := assert .New (t )
@@ -201,8 +199,16 @@ func (suite *QuerySuite) TestQueryAbort() {
201
199
// Ideally we would test that the sql query context is canceled, but
202
200
// go-sqlmock does not have something like ExpectContextCancellation
203
201
204
- mockRows := sqlmock .NewRows ([]string {"a" , "b" , "c" , "d" })
205
- suite .mock .ExpectQuery (".*" ).WillDelayFor (2 * time .Second ).WillReturnRows (mockRows )
202
+ mockRows := sqlmock .NewRows ([]string {"a" , "b" , "c" , "d" }).AddRow (1 , "one" , 1.5 , 100 )
203
+ suite .mock .ExpectQuery (`select \* from repositories` ).WillDelayFor (2 * time .Second ).WillReturnRows (mockRows )
204
+
205
+ mockProcessRows := sqlmock .NewRows (
206
+ []string {"Id" , "User" , "Host" , "db" , "Command" , "Time" , "State" , "Info" }).
207
+ AddRow (1234 , nil , "localhost:3306" , nil , "query" , 2 , "SquashedTable(refs, commit_files, files)(1/5)" , "select * from files" ).
208
+ AddRow (1288 , nil , "localhost:3306" , nil , "query" , 2 , "SquashedTable(refs, commit_files, files)(1/5)" , "select * from repositories" )
209
+ suite .mock .ExpectQuery ("SHOW FULL PROCESSLIST" ).WillReturnRows (mockProcessRows )
210
+
211
+ suite .mock .ExpectExec ("KILL 1288" )
206
212
207
213
json := `{"query": "select * from repositories"}`
208
214
req , _ := http .NewRequest ("POST" , "/query" , strings .NewReader (json ))
@@ -227,6 +233,11 @@ func (suite *QuerySuite) TestQueryAbort() {
227
233
handler .ServeHTTP (res , req )
228
234
}()
229
235
236
+ // Without this wait the Request is cancelled before the handler has time to
237
+ // start the query. Which also works fine, but we want to test a cancellation
238
+ // for a query that is in progress
239
+ time .Sleep (200 * time .Millisecond )
240
+
230
241
cancel ()
231
242
232
243
wg .Wait ()
0 commit comments