@@ -83,8 +83,6 @@ func (suite *QuerySuite) TestBadRequest() {
8383 `{"query": "select * from repositories", "limit": "string"}` ,
8484 }
8585
86- suite .mock .ExpectQuery (".*" ).WillReturnError (fmt .Errorf ("forced err" ))
87-
8886 for _ , tc := range testCases {
8987 suite .T ().Run (tc , func (t * testing.T ) {
9088 a := assert .New (t )
@@ -201,8 +199,16 @@ func (suite *QuerySuite) TestQueryAbort() {
201199 // Ideally we would test that the sql query context is canceled, but
202200 // go-sqlmock does not have something like ExpectContextCancellation
203201
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" )
206212
207213 json := `{"query": "select * from repositories"}`
208214 req , _ := http .NewRequest ("POST" , "/query" , strings .NewReader (json ))
@@ -227,6 +233,11 @@ func (suite *QuerySuite) TestQueryAbort() {
227233 handler .ServeHTTP (res , req )
228234 }()
229235
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+
230241 cancel ()
231242
232243 wg .Wait ()
0 commit comments