Skip to content
8 changes: 5 additions & 3 deletions v2/tests/admin_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func Test_ClusterMoveShards(t *testing.T) {

t.Run("Check if shards are moved", func(t *testing.T) {
start := time.Now()
maxTestTime := 2 * time.Minute
maxTestTime := 5 * time.Minute
lastShardsNotOnTargetServerID := movedShards

for {
Expand Down Expand Up @@ -320,7 +320,7 @@ func Test_ClusterResignLeadership(t *testing.T) {

t.Run("Check if targetServerID is no longer leader", func(t *testing.T) {
start := time.Now()
maxTestTime := time.Minute
maxTestTime := 5 * time.Minute
lastLeaderForShardsNum := 0

for {
Expand Down Expand Up @@ -444,7 +444,7 @@ func waitForDBServerClusterMaintenance(ctx context.Context, client arangodb.Clie

func Test_DBServerMaintenance(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
withContextT(t, defaultTestTimeout*3, func(ctx context.Context, tb testing.TB) {
requireClusterMode(t)
skipBelowVersion(client, ctx, "3.10", t)

Expand Down Expand Up @@ -501,6 +501,8 @@ func Test_DBServerMaintenance(t *testing.T) {
err = waitForDBServerClusterMaintenance(ctx, client, nil, dbServerId, 10*time.Second)
require.NoError(t, err, "maintenance mode not disabled in time")
})
}, WrapOptions{
Parallel: utils.NewType(false),
})
}

Expand Down
40 changes: 27 additions & 13 deletions v2/tests/database_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/arangodb/go-driver/v2/arangodb"
"github.com/arangodb/go-driver/v2/arangodb/shared"
"github.com/arangodb/go-driver/v2/utils"
)

Expand Down Expand Up @@ -326,7 +327,7 @@ func Test_ListOfRunningAQLQueries(t *testing.T) {
FOR x IN 1..100
RETURN x * i
)
RETURN {i: i, sum: SUM(computation)}
RETURN {i: i, sum: SUM(computation), sleep: SLEEP(1)}
`, &arangodb.QueryOptions{
BindVars: bindVars,
})
Expand Down Expand Up @@ -457,6 +458,7 @@ func Test_ListOfSlowAQLQueries(t *testing.T) {

func Test_KillAQLQuery(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
bvString := "maxKill" + StringWithCharset(16, charset)
ctx := context.Background()
// Get the database
db, err := client.GetDatabase(ctx, "_system", nil)
Expand Down Expand Up @@ -485,16 +487,16 @@ func Test_KillAQLQuery(t *testing.T) {

// Use a streaming query that processes results slowly
bindVars := map[string]interface{}{
"max": 10000000,
bvString: 10000000,
}

cursor, err := db.Query(ctx, `
FOR i IN 1..@max
FOR i IN 1..@`+bvString+`
LET computation = (
FOR x IN 1..100
RETURN x * i
)
RETURN {i: i, sum: SUM(computation)}
RETURN {i: i, sum: SUM(computation), j: SLEEP(2)}
`, &arangodb.QueryOptions{
BindVars: bindVars,
})
Expand All @@ -505,6 +507,7 @@ func Test_KillAQLQuery(t *testing.T) {
}
return
}
t.Logf("Query launched: %v", cursor)

// Process results slowly to keep query active longer
if cursor != nil {
Expand Down Expand Up @@ -547,19 +550,30 @@ func Test_KillAQLQuery(t *testing.T) {
t.Logf("Attempt %d: Found %d queries", attempt+1, len(queries))

if len(queries) > 0 {
foundRunningQuery = true
t.Logf("SUCCESS: Found %d running queries on attempt %d\n", len(queries), attempt+1)
// Log query details
for i, query := range queries {
bindVarsJSON, _ := utils.ToJSONString(*query.BindVars)
t.Logf("Query %d: ID=%s, State=%s, BindVars=%s",
i, *query.Id, *query.State, bindVarsJSON)
// Kill the query
err := db.KillAQLQuery(ctx, *query.Id, utils.NewType(false))
require.NoError(t, err, "Failed to kill query %s", *query.Id)
t.Logf("Killed query %s", *query.Id)
if strings.Contains(bindVarsJSON, bvString) {
t.Logf("Query %d: ID=%s, State=%s, BindVars=%s",
i, *query.Id, *query.State, bindVarsJSON)
// Kill the query
err := db.KillAQLQuery(ctx, *query.Id, utils.NewType(false))
if ok, arangoErr := shared.IsArangoError(err); ok {
if arangoErr.ErrorNum == shared.ErrQueryNotFound {
t.Logf("query gone %s", *query.Id)
continue
}
}
require.NoError(t, err, "Failed to kill query %s", *query.Id)
foundRunningQuery = true
t.Logf("Killed query %s", *query.Id)
break
} else {
t.Logf("Query skipped %d: ID=%s, State=%s, BindVars=%s",
i, *query.Id, *query.State, bindVarsJSON)
}
}
break
}

time.Sleep(300 * time.Millisecond)
Expand Down Expand Up @@ -1271,7 +1285,7 @@ func Test_UserDefinedFunctions(t *testing.T) {
require.NoError(t, err)

// Define UDF details
namespace := "myfunctions::temperature"
namespace := "myfunctions::temperature::" + StringWithCharset(16, charset)
functionName := namespace + "::celsiustofahrenheit"
code := "function (celsius) { return celsius * 9 / 5 + 32; }"

Expand Down
2 changes: 2 additions & 0 deletions v2/tests/database_transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
)

func Test_DatabaseCreateReplicationV2(t *testing.T) {
t.Skip("currently disabled")
Wrap(t, func(t *testing.T, client arangodb.Client) {
databaseReplication2Required(t, client, context.Background())

Expand Down Expand Up @@ -307,6 +308,7 @@ func abortTransaction(t testing.TB, transaction arangodb.Transaction) {
}

func databaseReplication2Required(t *testing.T, c arangodb.Client, ctx context.Context) {
t.Skip("currently disabled")
skipBelowVersion(c, context.Background(), "3.12.0", t)
requireClusterMode(t)

Expand Down
19 changes: 18 additions & 1 deletion v2/tests/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,28 @@ import (
"context"
"testing"

"math/rand"
"time"

"github.com/arangodb/go-driver/v2/arangodb"
"github.com/arangodb/go-driver/v2/utils"
"github.com/stretchr/testify/require"
)

const charset = "abcdefghijklmnopqrstuvwxyz" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))

func StringWithCharset(length int, charset string) string {
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}

type TaskParams struct {
Foo string `json:"foo"`
Bar string `json:"bar"`
Expand Down Expand Up @@ -138,7 +155,7 @@ func Test_TaskCreationWithId(t *testing.T) {
Wrap(t, func(t *testing.T, client arangodb.Client) {
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
dbName := "_system"
taskID := "test-task-id"
taskID := "test-task-id" + StringWithCharset(16, charset)
options := &arangodb.TaskOptions{
ID: &taskID, // Optional if CreateTaskWithID sets it, but safe to keep
Name: utils.NewType("TestTaskWithID"),
Expand Down
2 changes: 1 addition & 1 deletion v2/tests/utils_retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// defaultTestTimeout is the default timeout for context use in tests
// less than 2 minutes is causing problems on CI
const defaultTestTimeout = 15 * time.Minute
const defaultTestTimeout = 20 * time.Minute

type Timeout func() error

Expand Down