@@ -30,6 +30,7 @@ import (
3030 "github.com/stretchr/testify/require"
3131
3232 "github.com/arangodb/go-driver/v2/arangodb"
33+ "github.com/arangodb/go-driver/v2/arangodb/shared"
3334 "github.com/arangodb/go-driver/v2/utils"
3435)
3536
@@ -326,7 +327,7 @@ func Test_ListOfRunningAQLQueries(t *testing.T) {
326327 FOR x IN 1..100
327328 RETURN x * i
328329 )
329- RETURN {i: i, sum: SUM(computation)}
330+ RETURN {i: i, sum: SUM(computation), sleep: SLEEP(1) }
330331` , & arangodb.QueryOptions {
331332 BindVars : bindVars ,
332333 })
@@ -457,6 +458,7 @@ func Test_ListOfSlowAQLQueries(t *testing.T) {
457458
458459func Test_KillAQLQuery (t * testing.T ) {
459460 Wrap (t , func (t * testing.T , client arangodb.Client ) {
461+ bvString := "maxKill" + StringWithCharset (16 , charset )
460462 ctx := context .Background ()
461463 // Get the database
462464 db , err := client .GetDatabase (ctx , "_system" , nil )
@@ -485,16 +487,16 @@ func Test_KillAQLQuery(t *testing.T) {
485487
486488 // Use a streaming query that processes results slowly
487489 bindVars := map [string ]interface {}{
488- "max" : 10000000 ,
490+ bvString : 10000000 ,
489491 }
490492
491493 cursor , err := db .Query (ctx , `
492- FOR i IN 1..@max
494+ FOR i IN 1..@` + bvString + `
493495 LET computation = (
494496 FOR x IN 1..100
495497 RETURN x * i
496498 )
497- RETURN {i: i, sum: SUM(computation)}
499+ RETURN {i: i, sum: SUM(computation), j: SLEEP(2) }
498500` , & arangodb.QueryOptions {
499501 BindVars : bindVars ,
500502 })
@@ -505,6 +507,7 @@ func Test_KillAQLQuery(t *testing.T) {
505507 }
506508 return
507509 }
510+ t .Logf ("Query launched: %v" , cursor )
508511
509512 // Process results slowly to keep query active longer
510513 if cursor != nil {
@@ -547,19 +550,30 @@ func Test_KillAQLQuery(t *testing.T) {
547550 t .Logf ("Attempt %d: Found %d queries" , attempt + 1 , len (queries ))
548551
549552 if len (queries ) > 0 {
550- foundRunningQuery = true
551553 t .Logf ("SUCCESS: Found %d running queries on attempt %d\n " , len (queries ), attempt + 1 )
552554 // Log query details
553555 for i , query := range queries {
554556 bindVarsJSON , _ := utils .ToJSONString (* query .BindVars )
555- t .Logf ("Query %d: ID=%s, State=%s, BindVars=%s" ,
556- i , * query .Id , * query .State , bindVarsJSON )
557- // Kill the query
558- err := db .KillAQLQuery (ctx , * query .Id , utils .NewType (false ))
559- require .NoError (t , err , "Failed to kill query %s" , * query .Id )
560- t .Logf ("Killed query %s" , * query .Id )
557+ if strings .Contains (bindVarsJSON , bvString ) {
558+ t .Logf ("Query %d: ID=%s, State=%s, BindVars=%s" ,
559+ i , * query .Id , * query .State , bindVarsJSON )
560+ // Kill the query
561+ err := db .KillAQLQuery (ctx , * query .Id , utils .NewType (false ))
562+ if ok , arangoErr := shared .IsArangoError (err ); ok {
563+ if arangoErr .ErrorNum == shared .ErrQueryNotFound {
564+ t .Logf ("query gone %s" , * query .Id )
565+ continue
566+ }
567+ }
568+ require .NoError (t , err , "Failed to kill query %s" , * query .Id )
569+ foundRunningQuery = true
570+ t .Logf ("Killed query %s" , * query .Id )
571+ break
572+ } else {
573+ t .Logf ("Query skipped %d: ID=%s, State=%s, BindVars=%s" ,
574+ i , * query .Id , * query .State , bindVarsJSON )
575+ }
561576 }
562- break
563577 }
564578
565579 time .Sleep (300 * time .Millisecond )
@@ -1271,7 +1285,7 @@ func Test_UserDefinedFunctions(t *testing.T) {
12711285 require .NoError (t , err )
12721286
12731287 // Define UDF details
1274- namespace := "myfunctions::temperature"
1288+ namespace := "myfunctions::temperature::" + StringWithCharset ( 16 , charset )
12751289 functionName := namespace + "::celsiustofahrenheit"
12761290 code := "function (celsius) { return celsius * 9 / 5 + 32; }"
12771291
0 commit comments