Skip to content

Commit d8a192f

Browse files
Lars Maierneunhoef
authored andcommitted
Added test for views in backup. (#212)
1 parent 095263e commit d8a192f

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

test/backup_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,93 @@ func ensureRemoteBackup(ctx context.Context, b driver.ClientBackup, t *testing.T
819819
}
820820
return id
821821
}
822+
823+
func TestBackupRestoreWithViews(t *testing.T) {
824+
c := createClientFromEnv(t, true)
825+
skipIfNoBackup(c, t)
826+
ctx := context.Background()
827+
b := c.Backup()
828+
829+
isSingle := false
830+
if role, err := c.ServerRole(ctx); err != nil {
831+
t.Fatalf("Failed to obtain server role: %s", describe(err))
832+
} else {
833+
isSingle = role == driver.ServerRoleSingle
834+
}
835+
836+
dbname := "backup"
837+
colname := "col_views_docs"
838+
viewname := "backup_view"
839+
840+
trueVar := true
841+
842+
db := ensureDatabase(ctx, c, dbname, nil, t)
843+
col := ensureCollection(ctx, db, colname, nil, t)
844+
ensureArangoSearchView(ctx, db, viewname, &driver.ArangoSearchViewProperties{
845+
Links: driver.ArangoSearchLinks{
846+
colname: driver.ArangoSearchElementProperties{
847+
IncludeAllFields: &trueVar,
848+
},
849+
},
850+
}, t)
851+
852+
const numThreads = 10
853+
const numDocs = 10000
854+
const totalNumDocs = numThreads * numDocs
855+
856+
var wg sync.WaitGroup
857+
for k := 0; k < numThreads; k++ {
858+
wg.Add(1)
859+
go func(i int) {
860+
defer wg.Done()
861+
862+
for j := 0; j < numDocs; j++ {
863+
864+
book := BookWithAuthor{
865+
Title: fmt.Sprintf("Hello World - %d", j),
866+
Author: fmt.Sprintf("Author - %d", i),
867+
}
868+
869+
_, err := col.CreateDocument(ctx, book)
870+
if err != nil {
871+
t.Fatalf("Failed to create document %s", describe(err))
872+
}
873+
}
874+
}(k)
875+
}
876+
wg.Wait()
877+
878+
id, _, err := b.Create(ctx, nil)
879+
if err != nil {
880+
t.Fatalf("Failed to create backup: %s", describe(err))
881+
}
882+
883+
// Now restore
884+
if err := b.Restore(ctx, id, nil); err != nil {
885+
t.Fatalf("Failed to restore backup: %s", describe(err))
886+
}
887+
888+
if isSingle {
889+
waitctx, cancel := context.WithTimeout(ctx, 30*time.Second)
890+
defer cancel()
891+
waitForServerRestart(waitctx, c, t)
892+
}
893+
894+
// run query to get document count of view
895+
cursor, err := db.Query(ctx, fmt.Sprintf("FOR x IN %s COLLECT WITH COUNT INTO n RETURN n", viewname), nil)
896+
if err != nil {
897+
t.Fatalf("Failed to create query: %s", describe(err))
898+
}
899+
900+
defer cursor.Close()
901+
902+
var numDocumentsInView int
903+
_, err = cursor.ReadDocument(ctx, &numDocumentsInView)
904+
if err != nil {
905+
t.Fatalf("Failed to get document count: %s", describe(err))
906+
}
907+
908+
if numDocumentsInView != totalNumDocs {
909+
t.Errorf("Wrong number of documents: found: %d, expected: %d", numDocumentsInView, totalNumDocs)
910+
}
911+
}

test/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ type Book struct {
4242
Title string
4343
}
4444

45+
type BookWithAuthor struct {
46+
Title string
47+
Author string
48+
}
49+
4550
type RouteEdge struct {
4651
From string `json:"_from,omitempty"`
4752
To string `json:"_to,omitempty"`

0 commit comments

Comments
 (0)