Skip to content

Commit e082d30

Browse files
authored
ensure tests clean up the resources they create in the test flow (#689)
- increase timeouts for various actions - add defferred database cleanup - have more informative error messages - disable replication 2 tests - disable license tests, for post 3.12.4 versions, it works different now.
1 parent e58e3cf commit e082d30

File tree

71 files changed

+2392
-144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2392
-144
lines changed

test/arangosearch_analyzers_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ func TestArangoSearchAnalyzerEnsureAnalyzer(t *testing.T) {
8383

8484
dbname := "analyzer_test_ensure"
8585
db := ensureDatabase(ctx, c, dbname, nil, t)
86+
defer func() {
87+
err := db.Remove(ctx)
88+
if err != nil {
89+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
90+
}
91+
}()
8692

8793
testCases := []struct {
8894
Name string
@@ -444,6 +450,12 @@ func TestArangoSearchAnalyzerGet(t *testing.T) {
444450

445451
dbname := "analyzer_test_get"
446452
db := ensureDatabase(ctx, c, dbname, nil, t)
453+
defer func() {
454+
err := db.Remove(ctx)
455+
if err != nil {
456+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
457+
}
458+
}()
447459
aname := "my-ngram"
448460
def := driver.ArangoSearchAnalyzerDefinition{
449461
Name: aname,
@@ -478,6 +490,12 @@ func TestArangoSearchAnalyzerGetAll(t *testing.T) {
478490

479491
dbname := "analyzer_test_get_all"
480492
db := ensureDatabase(ctx, c, dbname, nil, t)
493+
defer func() {
494+
err := db.Remove(ctx)
495+
if err != nil {
496+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
497+
}
498+
}()
481499
aname := "my-ngram"
482500
def := driver.ArangoSearchAnalyzerDefinition{
483501
Name: aname,
@@ -518,6 +536,12 @@ func TestArangoSearchAnalyzerRemove(t *testing.T) {
518536

519537
dbname := "analyzer_test_get_all"
520538
db := ensureDatabase(ctx, c, dbname, nil, t)
539+
defer func() {
540+
err := db.Remove(ctx)
541+
if err != nil {
542+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
543+
}
544+
}()
521545
aname := "my-ngram"
522546
def := driver.ArangoSearchAnalyzerDefinition{
523547
Name: aname,

test/asyncjob_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ func TestAsyncJobListPending(t *testing.T) {
102102
skipResilientSingle(t)
103103

104104
db := ensureDatabase(ctx, c, databaseName("db", "async"), nil, t)
105-
defer db.Remove(ctx)
105+
defer func() {
106+
err := db.Remove(ctx)
107+
if err != nil {
108+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
109+
}
110+
}()
106111
col := ensureCollection(ctx, db, "frontend", nil, t)
107112

108113
idTransaction := runLongRequest(t, ctxAsync, db, 2, col.Name())
@@ -145,7 +150,12 @@ func TestAsyncJobCancel(t *testing.T) {
145150
skipResilientSingle(t)
146151

147152
db := ensureDatabase(ctx, c, databaseName("db", "async", "cancel"), nil, t)
148-
defer db.Remove(ctx)
153+
defer func() {
154+
err := db.Remove(ctx)
155+
if err != nil {
156+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
157+
}
158+
}()
149159

150160
aqlQuery := "FOR i IN 1..10 FOR j IN 1..10 LET x = sleep(1.0) FILTER i == 5 && j == 5 RETURN 42"
151161
_, err := db.Query(ctxAsync, aqlQuery, nil)
@@ -192,7 +202,12 @@ func TestAsyncJobDelete(t *testing.T) {
192202
skipResilientSingle(t)
193203

194204
db := ensureDatabase(ctx, c, databaseName("db", "async", "cancel"), nil, t)
195-
defer db.Remove(ctx)
205+
defer func() {
206+
err := db.Remove(ctx)
207+
if err != nil {
208+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
209+
}
210+
}()
196211
col := ensureCollection(ctx, db, "backend", nil, t)
197212

198213
t.Run("delete all jobs", func(t *testing.T) {

test/backup_test.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func waitForServerRestart(ctx context.Context, c driver.Client, t *testing.T) dr
314314
}
315315

316316
return nil
317-
}).RetryT(t, 100*time.Millisecond, 15*time.Second)
317+
}).RetryT(t, 100*time.Millisecond, 30*time.Second)
318318

319319
// Wait for secret to start
320320
newRetryFunc(func() error {
@@ -327,7 +327,7 @@ func waitForServerRestart(ctx context.Context, c driver.Client, t *testing.T) dr
327327
}
328328

329329
return nil
330-
}).RetryT(t, 100*time.Millisecond, 15*time.Second)
330+
}).RetryT(t, 100*time.Millisecond, 30*time.Second)
331331

332332
return c
333333
}
@@ -354,6 +354,13 @@ func TestBackupRestore(t *testing.T) {
354354
colname := "col"
355355

356356
db := ensureDatabase(ctx, c, dbname, nil, t)
357+
defer func() {
358+
err := db.Remove(ctx)
359+
if err != nil {
360+
t.Logf("Failed to drop database %s: %s ...", dbname, err)
361+
}
362+
}()
363+
357364
col := ensureCollection(ctx, db, colname, nil, t)
358365

359366
// Write a document
@@ -576,6 +583,12 @@ func TestBackupCompleteCycle(t *testing.T) {
576583
colname := "col"
577584

578585
db := ensureDatabase(ctx, c, dbname, nil, t)
586+
defer func() {
587+
err := db.Remove(ctx)
588+
if err != nil {
589+
t.Logf("Failed to drop database %s: %s ...", dbname, err)
590+
}
591+
}()
579592
col := ensureCollection(ctx, db, colname, nil, t)
580593

581594
isSingle := false
@@ -750,6 +763,12 @@ func TestBackupRestoreWithViews(t *testing.T) {
750763
trueVar := true
751764

752765
db := ensureDatabase(ctx, c, dbname, nil, t)
766+
defer func() {
767+
err := db.Remove(ctx)
768+
if err != nil {
769+
t.Logf("Failed to drop database %s: %s ...", dbname, err)
770+
}
771+
}()
753772
col := ensureCollection(ctx, db, colname, nil, t)
754773
ensureArangoSearchView(ctx, db, viewname, &driver.ArangoSearchViewProperties{
755774
Links: driver.ArangoSearchLinks{
@@ -795,7 +814,7 @@ func TestBackupRestoreWithViews(t *testing.T) {
795814
defer waitForHealthyClusterAfterBackup(t, c)
796815

797816
if isSingle {
798-
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
817+
waitctx, cancel := context.WithTimeout(ctx, 60*time.Second)
799818
defer cancel()
800819
c = waitForServerRestart(waitctx, c, t)
801820
}

test/benchmark_collection_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import (
2929
func BenchmarkCollectionExists(b *testing.B) {
3030
c := createClient(b, nil)
3131
db := ensureDatabase(nil, c, "collection_test", nil, b)
32+
defer func() {
33+
err := db.Remove(nil)
34+
if err != nil {
35+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
36+
}
37+
}()
3238
col := ensureCollection(nil, db, "collection_exist_test", nil, b)
3339

3440
b.ResetTimer()
@@ -43,6 +49,12 @@ func BenchmarkCollectionExists(b *testing.B) {
4349
func BenchmarkCollection(b *testing.B) {
4450
c := createClient(b, nil)
4551
db := ensureDatabase(nil, c, "collection_test", nil, b)
52+
defer func() {
53+
err := db.Remove(nil)
54+
if err != nil {
55+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
56+
}
57+
}()
4658
col := ensureCollection(nil, db, "collection_test", nil, b)
4759

4860
b.ResetTimer()
@@ -57,6 +69,12 @@ func BenchmarkCollection(b *testing.B) {
5769
func BenchmarkCollections(b *testing.B) {
5870
c := createClient(b, nil)
5971
db := ensureDatabase(nil, c, "collection_test", nil, b)
72+
defer func() {
73+
err := db.Remove(nil)
74+
if err != nil {
75+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
76+
}
77+
}()
6078
for i := 0; i < 10; i++ {
6179
ensureCollection(nil, db, fmt.Sprintf("col%d", i), nil, b)
6280
}

test/benchmark_document_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ import "testing"
2626
func BenchmarkCreateDocument(b *testing.B) {
2727
c := createClient(b, nil)
2828
db := ensureDatabase(nil, c, "document_test", nil, b)
29+
defer func() {
30+
err := db.Remove(nil)
31+
if err != nil {
32+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
33+
}
34+
}()
2935
col := ensureCollection(nil, db, "document_test", nil, b)
3036

3137
b.ResetTimer()
@@ -44,6 +50,12 @@ func BenchmarkCreateDocument(b *testing.B) {
4450
func BenchmarkCreateDocumentParallel(b *testing.B) {
4551
c := createClient(b, nil)
4652
db := ensureDatabase(nil, c, "document_test", nil, b)
53+
defer func() {
54+
err := db.Remove(nil)
55+
if err != nil {
56+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
57+
}
58+
}()
4759
col := ensureCollection(nil, db, "document_test", nil, b)
4860

4961
b.SetParallelism(100)
@@ -64,6 +76,12 @@ func BenchmarkCreateDocumentParallel(b *testing.B) {
6476
func BenchmarkReadDocument(b *testing.B) {
6577
c := createClient(b, nil)
6678
db := ensureDatabase(nil, c, "document_test", nil, b)
79+
defer func() {
80+
err := db.Remove(nil)
81+
if err != nil {
82+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
83+
}
84+
}()
6785
col := ensureCollection(nil, db, "document_test", nil, b)
6886
doc := UserDoc{
6987
"Jan",
@@ -87,6 +105,12 @@ func BenchmarkReadDocument(b *testing.B) {
87105
func BenchmarkReadDocumentParallel(b *testing.B) {
88106
c := createClient(b, nil)
89107
db := ensureDatabase(nil, c, "document_test", nil, b)
108+
defer func() {
109+
err := db.Remove(nil)
110+
if err != nil {
111+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
112+
}
113+
}()
90114
col := ensureCollection(nil, db, "document_test", nil, b)
91115
doc := UserDoc{
92116
"Jan",
@@ -112,6 +136,12 @@ func BenchmarkReadDocumentParallel(b *testing.B) {
112136
func BenchmarkRemoveDocument(b *testing.B) {
113137
c := createClient(b, nil)
114138
db := ensureDatabase(nil, c, "document_test", nil, b)
139+
defer func() {
140+
err := db.Remove(nil)
141+
if err != nil {
142+
b.Logf("Failed to drop database %s: %s ...", db.Name(), err)
143+
}
144+
}()
115145
col := ensureCollection(nil, db, "document_test", nil, b)
116146

117147
b.ResetTimer()

test/client_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ func TestResponseHeader(t *testing.T) {
496496
} else {
497497
var resp driver.Response
498498
db := ensureDatabase(ctx, c, "_system", nil, t)
499+
defer func() {
500+
err := db.Remove(ctx)
501+
if err != nil {
502+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
503+
}
504+
}()
499505
col := ensureCollection(ctx, db, "response_header_test", nil, t)
500506
defer clean(t, ctx, col)
501507

@@ -579,6 +585,21 @@ func TestClientConnectionReuse(t *testing.T) {
579585
Options: driver.CreateDatabaseDefaultOptions{},
580586
}, t)
581587
}
588+
defer func() {
589+
for dbName, user := range dbUsers {
590+
t.Logf("Dropping DB %s ...", dbName)
591+
db := ensureDatabase(ctx, c, dbName, nil, t)
592+
err := db.Remove(ctx)
593+
if err != nil {
594+
t.Logf("Failed to drop database %s: %s ...", dbName, err)
595+
}
596+
u := ensureUser(ctx, c, user.UserName, nil, t)
597+
err = u.Remove(ctx)
598+
if err != nil {
599+
t.Logf("Failed to delete user %s: %s ...", user.UserName, err)
600+
}
601+
}
602+
}()
582603

583604
var wg sync.WaitGroup
584605
const clientsPerDB = 20

test/collection_schema_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func TestCollectionSchema(t *testing.T) {
5151

5252
name := "document_schema_validation_test"
5353
db := ensureDatabase(nil, c, name, nil, t)
54+
defer func() {
55+
err := db.Remove(nil)
56+
if err != nil {
57+
t.Logf("Failed to drop database %s: %s ...", db.Name(), err)
58+
}
59+
}()
5460
t.Run("Create collection with schema validation", func(t *testing.T) {
5561
opts := driver.CreateCollectionOptions{
5662
Schema: &driver.CollectionSchemaOptions{

0 commit comments

Comments
 (0)