Skip to content

Commit ed6c2a9

Browse files
authored
[Tests] Add backup delays (#375)
1 parent e985a4b commit ed6c2a9

File tree

2 files changed

+53
-69
lines changed

2 files changed

+53
-69
lines changed

test/backup_test.go

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ import (
3636
driver "github.com/arangodb/go-driver"
3737
)
3838

39+
func waitForHealthyClusterAfterBackup(t *testing.T, client driver.Client) {
40+
time.Sleep(5 * time.Second)
41+
waitForHealthyCluster(t, client, 2*time.Second).RetryT(t, 125*time.Millisecond, 10*time.Second)
42+
}
43+
3944
var backupAPIAvailable *bool
4045

4146
func setBackupAvailable(av bool) {
@@ -421,6 +426,7 @@ func TestBackupRestore(t *testing.T) {
421426
if err := b.Restore(ctx, id, nil); err != nil {
422427
t.Fatalf("Failed to restore backup: %s", describe(err))
423428
}
429+
defer waitForHealthyClusterAfterBackup(t, c)
424430

425431
if isSingle {
426432
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
@@ -672,6 +678,7 @@ func TestBackupCompleteCycle(t *testing.T) {
672678
if err := b.Restore(ctx, id, nil); err != nil {
673679
t.Fatalf("Failed to restore backup: %s", describe(err))
674680
}
681+
defer waitForHealthyClusterAfterBackup(t, c)
675682

676683
if isSingle {
677684
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
@@ -759,75 +766,6 @@ func TestBackupCreateManyBackupsFast(t *testing.T) {
759766
}
760767
}
761768

762-
func TestBackupCreateRestoreParallel(t *testing.T) {
763-
c := createClientFromEnv(t, true)
764-
skipIfNoBackup(c, t)
765-
766-
ctx := context.Background()
767-
b := c.Backup()
768-
id := ensureBackup(ctx, b, t)
769-
770-
isSingle := false
771-
if role, err := c.ServerRole(ctx); err != nil {
772-
t.Fatalf("Failed to obtain server role: %s", describe(err))
773-
} else {
774-
isSingle = role == driver.ServerRoleSingle
775-
}
776-
777-
errchan := make(chan error)
778-
defer close(errchan)
779-
var wg sync.WaitGroup
780-
781-
wg.Add(1)
782-
go func() {
783-
defer wg.Done()
784-
if _, _, err := b.Create(ctx, nil); err == nil {
785-
errchan <- nil
786-
} else {
787-
errchan <- err
788-
t.Logf("Create failed: %s", describe(err))
789-
}
790-
}()
791-
wg.Add(1)
792-
go func() {
793-
defer wg.Done()
794-
if err := b.Restore(ctx, id, nil); err == nil {
795-
errchan <- nil
796-
if isSingle {
797-
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
798-
defer cancel()
799-
c = waitForServerRestart(waitctx, c, t)
800-
}
801-
} else {
802-
errchan <- err
803-
t.Logf("Restore failed: %s", describe(err))
804-
}
805-
}()
806-
807-
errCount := 0
808-
for i := 0; i < 2; i++ {
809-
err := <-errchan
810-
if err != nil {
811-
errCount++
812-
}
813-
}
814-
815-
wg.Wait()
816-
817-
if errCount >= 2 {
818-
t.Fatalf("Both operation failed!")
819-
}
820-
}
821-
822-
func ensureRemoteBackup(ctx context.Context, b driver.ClientBackup, t *testing.T) driver.BackupID {
823-
id := ensureBackup(ctx, b, t)
824-
uploadBackupWaitForCompletion(ctx, id, b, t)
825-
if err := b.Delete(ctx, id); err != nil {
826-
t.Fatalf("Failed to remove backup: %s", err)
827-
}
828-
return id
829-
}
830-
831769
func TestBackupRestoreWithViews(t *testing.T) {
832770
c := createClientFromEnv(t, true)
833771
skipIfNoBackup(c, t)
@@ -890,6 +828,7 @@ func TestBackupRestoreWithViews(t *testing.T) {
890828
if err := b.Restore(ctx, id, nil); err != nil {
891829
t.Fatalf("Failed to restore backup: %s", describe(err))
892830
}
831+
defer waitForHealthyClusterAfterBackup(t, c)
893832

894833
if isSingle {
895834
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)

test/util.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,48 @@ func getCallerFunctionName() string {
229229

230230
return function[0] + "_" + uniuri.NewLen(6)
231231
}
232+
233+
func waitForHealthyCluster(t *testing.T, client driver.Client, timeout time.Duration) retryFunc {
234+
return func() error {
235+
ctx, c := context.WithTimeout(context.Background(), timeout)
236+
defer c()
237+
238+
cluster, err := client.Cluster(ctx)
239+
if err != nil {
240+
if !driver.IsPreconditionFailed(err) {
241+
t.Logf("Unable to get cluster: %s", err.Error())
242+
return nil
243+
}
244+
// We are on single, check version
245+
246+
_, err = client.Version(ctx)
247+
if err == nil {
248+
return interrupt{}
249+
}
250+
251+
t.Logf("Unable to get version: %s", err.Error())
252+
return nil
253+
}
254+
255+
health, err := cluster.Health(ctx)
256+
if err != nil {
257+
t.Logf("Unable to get health: %s", err.Error())
258+
return nil
259+
}
260+
261+
healthy := true
262+
263+
for id, m := range health.Health {
264+
if m.Status != driver.ServerStatusGood {
265+
healthy = false
266+
t.Logf("Server %s in bad health: %s", id, m.Status)
267+
}
268+
}
269+
270+
if healthy {
271+
return interrupt{}
272+
}
273+
274+
return nil
275+
}
276+
}

0 commit comments

Comments
 (0)