Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Dec 22, 2024
1 parent 0fcbd4c commit e8a0249
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
3 changes: 0 additions & 3 deletions dgraphtest/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ func init() {
if err != nil {
panic(err)
}
if err := ensureDgraphClone(); err != nil {
panic(err)
}

log.Printf("[INFO] baseRepoDir: %v", baseRepoDir)
log.Printf("[INFO] repoDir: %v", repoDir)
Expand Down
60 changes: 46 additions & 14 deletions systest/21million/bulk/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
package bulk

import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"

"github.com/dgraph-io/dgraph/v24/chunker"
"github.com/dgraph-io/dgraph/v24/systest/21million/common"
"github.com/dgraph-io/dgraph/v24/testutil"
)
Expand All @@ -31,26 +38,51 @@ func TestQueries(t *testing.T) {
t.Run("Run queries", common.TestQueriesFor21Million)
}

func TestMain(m *testing.M) {
schemaFile := filepath.Join(testutil.TestDataDirectory, "21million.schema")
rdfFile := filepath.Join(testutil.TestDataDirectory, "21million.rdf.gz")
if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil {
os.Exit(1)
func BenchmarkQueries(b *testing.B) {

_, thisFile, _, _ := runtime.Caller(0)
queryDir := filepath.Join(filepath.Dir(thisFile), "../queries")

// For this test we DON'T want to start with an empty database.
dg, err := testutil.DgraphClient(testutil.ContainerAddr("alpha1", 9080))
if err != nil {
panic(fmt.Sprintf("Error while getting a dgraph client: %v", err))
}

if err := testutil.BulkLoad(testutil.BulkOpts{
Zero: testutil.SockAddrZero,
Shards: 1,
RdfFile: rdfFile,
SchemaFile: schemaFile,
}); err != nil {
cleanupAndExit(1)
files, err := os.ReadDir(queryDir)
if err != nil {
panic(fmt.Sprintf("Error reading directory: %s", err.Error()))
}

if err := testutil.StartAlphas("./alpha.yml"); err != nil {
cleanupAndExit(1)
//savepath := ""
//diffs := 0
for _, file := range files {
if !strings.HasPrefix(file.Name(), "query-") {
continue
}
b.Run(file.Name(), func(b *testing.B) {
filename := filepath.Join(queryDir, file.Name())
reader, cleanup := chunker.FileReader(filename, nil)
bytes, _ := io.ReadAll(reader)
contents := string(bytes[:])
cleanup()

// The test query and expected result are separated by a delimiter.
bodies := strings.SplitN(contents, "\n---\n", 2)
// Dgraph can get into unhealthy state sometime. So, add retry for every query.
// If a query takes too long to run, it probably means dgraph is stuck and there's
// no point in waiting longer or trying more tests.
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
_, err := dg.NewTxn().Query(ctx, bodies[0])
if err != nil {
panic(err)
}
cancel()
})
}
}

func TestMain(m *testing.M) {
exitCode := m.Run()
cleanupAndExit(exitCode)
}
Expand Down

0 comments on commit e8a0249

Please sign in to comment.