Skip to content

Commit fe38f89

Browse files
authored
OAS-9946 Handle DB creation failures in tests. (#616)
1 parent a721cfa commit fe38f89

File tree

4 files changed

+55
-10
lines changed

4 files changed

+55
-10
lines changed

test/backup_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ func waitForServerRestart(ctx context.Context, c driver.Client, t *testing.T) dr
333333
}
334334

335335
func TestBackupRestore(t *testing.T) {
336+
if os.Getenv("TEST_CONNECTION") == "vst" {
337+
t.Skip("VST is dropped since 3.12")
338+
return
339+
}
340+
336341
c := createClient(t, nil)
337342
skipIfNoBackup(c, t)
338343
ctx := context.Background()
@@ -721,6 +726,11 @@ func TestBackupCreateManyBackupsFast(t *testing.T) {
721726
}
722727

723728
func TestBackupRestoreWithViews(t *testing.T) {
729+
if os.Getenv("TEST_CONNECTION") == "vst" {
730+
t.Skip("VST is dropped since 3.12")
731+
return
732+
}
733+
724734
c := createClient(t, nil)
725735
skipIfNoBackup(c, t)
726736
ctx := context.Background()

v2/arangodb/shared/error.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ func newArangoError(code, errorNum int, errorMessage string) error {
102102
}
103103
}
104104

105-
// IsArangoError returns true when the given error is an ArangoError.
106-
func IsArangoError(err error) bool {
107-
return checkCause(err, func(err error) bool {
108-
if a, ok := err.(ArangoError); ok {
109-
return a.HasError
110-
}
105+
// IsArangoError returns true when the given error is an ArangoError
106+
func IsArangoError(err error) (bool, ArangoError) {
107+
var arangoErr ArangoError
108+
ok := errors.As(err, &arangoErr)
111109

112-
return false
113-
})
110+
return ok, arangoErr
114111
}
115112

116113
// IsArangoErrorWithCode returns true when the given error is an ArangoError and its Code field is equal to the given code.

v2/tests/backup_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package tests
2323
import (
2424
"context"
2525
"encoding/json"
26+
"fmt"
2627
"os"
2728
"strings"
2829
"testing"
@@ -31,6 +32,7 @@ import (
3132
"github.com/stretchr/testify/require"
3233

3334
"github.com/arangodb/go-driver/v2/arangodb"
35+
"github.com/arangodb/go-driver/v2/arangodb/shared"
3436
)
3537

3638
func Test_CreateBackupSimple(t *testing.T) {
@@ -132,6 +134,8 @@ func Test_RestoreBackupSimple(t *testing.T) {
132134

133135
err = client.BackupDelete(ctx, backup.ID)
134136
require.NoError(t, err, "DeleteBackup failed")
137+
138+
waitForSync(t, ctx, client)
135139
})
136140
})
137141
})
@@ -140,6 +144,40 @@ func Test_RestoreBackupSimple(t *testing.T) {
140144
})
141145
}
142146

147+
/*
148+
Sometimes after restore, we observe the following error during db creation:
149+
150+
```
151+
Could not create database: executing createSystemCollectionsAndIndices
152+
(creates all system collections including their indices) failed.
153+
```
154+
155+
Looks like not all DB servers have reported ready in Current/DBServers in the agency when the database creation attempt runs.
156+
This could be the case if DB servers are all restarted (as after a hotbackup) and start reacting to liveliness probes each,
157+
but the coordinator has not yet fetched the latest agency state.
158+
There may be a small window of time in which a DB server already responds to `/_admin/server/availablity`,
159+
but has not reported ready to the agency, or the coordinator has not yet fetched the latest state from the agency and
160+
does not yet see the server available in Current/DBServers.
161+
*/
162+
func waitForSync(t *testing.T, ctx context.Context, client arangodb.Client) {
163+
NewTimeout(func() error {
164+
name := GenerateUUID("test-backup-DB")
165+
166+
db, err := client.CreateDatabase(ctx, name, nil)
167+
if err != nil {
168+
if ok, arangoErr := shared.IsArangoError(err); ok {
169+
t.Logf("waitForSync ERROR: errorNum: %d, errCode: %d, msg: %s", arangoErr.ErrorNum, arangoErr.Code, arangoErr.ErrorMessage)
170+
if strings.Contains(arangoErr.ErrorMessage, "executing createSystemCollectionsAndIndices (creates all system collections including their indices) failed") {
171+
return err
172+
}
173+
}
174+
}
175+
require.NoError(t, err, fmt.Sprintf("waitForSync Failed to create DB %s", name))
176+
require.NoError(t, db.Remove(ctx))
177+
return Interrupt{}
178+
}).TimeoutT(t, 2*time.Minute, 125*time.Millisecond)
179+
}
180+
143181
func Test_BackupFullFlow(t *testing.T) {
144182
requireClusterMode(t)
145183

@@ -184,6 +222,7 @@ func Test_BackupFullFlow(t *testing.T) {
184222
WaitForHealthyCluster(t, client, time.Minute, true)
185223
})
186224

225+
waitForSync(t, ctx, client)
187226
})
188227
}, WrapOptions{
189228
Parallel: newBool(false),

v2/tests/call_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@ func Test_CallWithChecks(t *testing.T) {
8484
[]int{http.StatusOK, http.StatusNoContent})
8585
require.Error(t, err)
8686

87-
arangoErr, ok := err.(shared.ArangoError)
87+
ok, arangoErr := shared.IsArangoError(err)
8888
require.True(t, ok)
8989
require.True(t, arangoErr.HasError)
90-
require.True(t, shared.IsArangoError(arangoErr))
9190
require.Equal(t, http.StatusNotFound, resp.Code())
9291
})
9392
})

0 commit comments

Comments
 (0)