Skip to content

Commit b78456c

Browse files
authored
make V2 tests stable in the arangodb CI (#692)
1 parent 35fcaea commit b78456c

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

v2/tests/admin_cluster_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func Test_ClusterMoveShards(t *testing.T) {
242242

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

248248
for {
@@ -320,7 +320,7 @@ func Test_ClusterResignLeadership(t *testing.T) {
320320

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

326326
for {
@@ -444,7 +444,7 @@ func waitForDBServerClusterMaintenance(ctx context.Context, client arangodb.Clie
444444

445445
func Test_DBServerMaintenance(t *testing.T) {
446446
Wrap(t, func(t *testing.T, client arangodb.Client) {
447-
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
447+
withContextT(t, defaultTestTimeout*3, func(ctx context.Context, tb testing.TB) {
448448
requireClusterMode(t)
449449
skipBelowVersion(client, ctx, "3.10", t)
450450

@@ -501,6 +501,8 @@ func Test_DBServerMaintenance(t *testing.T) {
501501
err = waitForDBServerClusterMaintenance(ctx, client, nil, dbServerId, 10*time.Second)
502502
require.NoError(t, err, "maintenance mode not disabled in time")
503503
})
504+
}, WrapOptions{
505+
Parallel: utils.NewType(false),
504506
})
505507
}
506508

v2/tests/database_query_test.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

458459
func 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

v2/tests/database_transactions_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
)
3535

3636
func Test_DatabaseCreateReplicationV2(t *testing.T) {
37+
t.Skip("currently disabled")
3738
Wrap(t, func(t *testing.T, client arangodb.Client) {
3839
databaseReplication2Required(t, client, context.Background())
3940

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

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

v2/tests/tasks_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,28 @@ import (
2424
"context"
2525
"testing"
2626

27+
"math/rand"
28+
"time"
29+
2730
"github.com/arangodb/go-driver/v2/arangodb"
2831
"github.com/arangodb/go-driver/v2/utils"
2932
"github.com/stretchr/testify/require"
3033
)
3134

35+
const charset = "abcdefghijklmnopqrstuvwxyz" +
36+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
37+
38+
var seededRand *rand.Rand = rand.New(
39+
rand.NewSource(time.Now().UnixNano()))
40+
41+
func StringWithCharset(length int, charset string) string {
42+
b := make([]byte, length)
43+
for i := range b {
44+
b[i] = charset[seededRand.Intn(len(charset))]
45+
}
46+
return string(b)
47+
}
48+
3249
type TaskParams struct {
3350
Foo string `json:"foo"`
3451
Bar string `json:"bar"`
@@ -138,7 +155,7 @@ func Test_TaskCreationWithId(t *testing.T) {
138155
Wrap(t, func(t *testing.T, client arangodb.Client) {
139156
withContextT(t, defaultTestTimeout, func(ctx context.Context, tb testing.TB) {
140157
dbName := "_system"
141-
taskID := "test-task-id"
158+
taskID := "test-task-id" + StringWithCharset(16, charset)
142159
options := &arangodb.TaskOptions{
143160
ID: &taskID, // Optional if CreateTaskWithID sets it, but safe to keep
144161
Name: utils.NewType("TestTaskWithID"),

v2/tests/utils_retry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

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

3636
type Timeout func() error
3737

0 commit comments

Comments
 (0)