Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaji-dgraph committed May 21, 2024
1 parent 48e6e00 commit 766ddf5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 40 deletions.
8 changes: 8 additions & 0 deletions dgraphtest/dcloud_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ func (c *DCloudCluster) GetVersion() string {
func (c *DCloudCluster) GetRepoDir() (string, error) {
return "", errNotImplemented
}

func (c *DCloudCluster) AlphasLogs() ([]string, error) {
return nil, errNotImplemented
}

func (c *DCloudCluster) GetEncKeyPath() (string, error) {
return "", errNotImplemented
}
2 changes: 1 addition & 1 deletion query/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
x.Panic(dg.LoginIntoNamespace(ctx, dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

dc = c
client = dg.Dgraph
client.Dgraph = dg
populateCluster(dc)
m.Run()
}
5 changes: 3 additions & 2 deletions query/vector/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"context"
"testing"

"github.com/dgraph-io/dgraph/dgraphapi"
"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/x"
)
Expand All @@ -34,8 +35,8 @@ func TestMain(m *testing.M) {
client, cleanup, err = dc.Client()
x.Panic(err)
defer cleanup()
x.Panic(client.LoginIntoNamespace(context.Background(), dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
x.Panic(client.LoginIntoNamespace(context.Background(), dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

m.Run()
}
16 changes: 8 additions & 8 deletions query/vector/vector_graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"math/rand"
"testing"

"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/dgraphapi"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -89,7 +89,7 @@ func generateRandomTitleV(size int) []float32 {
return titleV
}

func addProject(t *testing.T, hc *dgraphtest.HTTPClient, project ProjectInput) {
func addProject(t *testing.T, hc *dgraphapi.HTTPClient, project ProjectInput) {
query := `
mutation addProject($project: AddProjectInput!) {
addProject(input: [$project]) {
Expand All @@ -100,7 +100,7 @@ func addProject(t *testing.T, hc *dgraphtest.HTTPClient, project ProjectInput) {
}
}`

params := dgraphtest.GraphQLParams{
params := dgraphapi.GraphQLParams{
Query: query,
Variables: map[string]interface{}{"project": project},
}
Expand All @@ -109,15 +109,15 @@ func addProject(t *testing.T, hc *dgraphtest.HTTPClient, project ProjectInput) {
require.NoError(t, err)
}

func queryProjectUsingTitle(t *testing.T, hc *dgraphtest.HTTPClient, title string) ProjectInput {
func queryProjectUsingTitle(t *testing.T, hc *dgraphapi.HTTPClient, title string) ProjectInput {
query := ` query QueryProject($title: String!) {
queryProject(filter: { title: { eq: $title } }) {
title
title_v
}
}`

params := dgraphtest.GraphQLParams{
params := dgraphapi.GraphQLParams{
Query: query,
Variables: map[string]interface{}{"title": title},
}
Expand All @@ -133,7 +133,7 @@ func queryProjectUsingTitle(t *testing.T, hc *dgraphtest.HTTPClient, title strin
return resp.QueryProject[0]
}

func queryProjectsSimilarByEmbedding(t *testing.T, hc *dgraphtest.HTTPClient, vector []float32, topk int) []ProjectInput {
func queryProjectsSimilarByEmbedding(t *testing.T, hc *dgraphapi.HTTPClient, vector []float32, topk int) []ProjectInput {
// query similar project by embedding
queryProduct := `query QuerySimilarProjectByEmbedding($by: ProjectEmbedding!, $topK: Int!, $vector: [Float!]!) {
querySimilarProjectByEmbedding(by: $by, topK: $topK, vector: $vector) {
Expand All @@ -144,7 +144,7 @@ func queryProjectsSimilarByEmbedding(t *testing.T, hc *dgraphtest.HTTPClient, ve
`

params := dgraphtest.GraphQLParams{
params := dgraphapi.GraphQLParams{
Query: queryProduct,
Variables: map[string]interface{}{
"by": "title_v",
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestVectorGraphQlDotProductIndexMutationAndQuery(t *testing.T) {
testVectorGraphQlMutationAndQuery(t, hc)
}

func testVectorGraphQlMutationAndQuery(t *testing.T, hc *dgraphtest.HTTPClient) {
func testVectorGraphQlMutationAndQuery(t *testing.T, hc *dgraphapi.HTTPClient) {
var vectors [][]float32
numProjects := 100
projects := generateProjects(numProjects)
Expand Down
9 changes: 5 additions & 4 deletions query/vector/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/dgraph-io/dgo/v230/protos/api"
"github.com/dgraph-io/dgraph/dgraphapi"
"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/x"
"github.com/stretchr/testify/require"
Expand All @@ -41,8 +42,8 @@ const (
vectorSchemaWithoutIndex = `%v: float32vector .`
)

var client *dgraphtest.GrpcClient
var dc dgraphtest.Cluster
var client *dgraphapi.GrpcClient
var dc dgraphapi.Cluster

func setSchema(schema string) {
var err error
Expand Down Expand Up @@ -445,8 +446,8 @@ func TestVectorDeadlockwithTimeout(t *testing.T) {
fmt.Println("Testing iteration: ", i)
ctx, cancel2 := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel2()
err = client.LoginIntoNamespace(ctx, dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace)
err = client.LoginIntoNamespace(ctx, dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace)
require.NoError(t, err)

err = client.Alter(context.Background(), &api.Operation{
Expand Down
45 changes: 23 additions & 22 deletions systest/vector/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"github.com/dgraph-io/dgo/v230/protos/api"
"github.com/dgraph-io/dgraph/dgraphapi"
"github.com/dgraph-io/dgraph/dgraphtest"
"github.com/dgraph-io/dgraph/x"
"github.com/stretchr/testify/require"
Expand All @@ -43,12 +44,12 @@ func TestVectorIncrBackupRestore(t *testing.T) {
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.SetupSchema(testSchema))

Expand All @@ -59,7 +60,7 @@ func TestVectorIncrBackupRestore(t *testing.T) {
for i := 1; i <= 5; i++ {
var rdfs string
var vectors [][]float32
rdfs, vectors = dgraphtest.GenerateRandomVectors(numVectors*(i-1), numVectors*i, 1, pred)
rdfs, vectors = dgraphapi.GenerateRandomVectors(numVectors*(i-1), numVectors*i, 1, pred)
allVectors = append(allVectors, vectors)
allRdfs = append(allRdfs, rdfs)
mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
Expand All @@ -75,7 +76,7 @@ func TestVectorIncrBackupRestore(t *testing.T) {

incrFrom := i - 1
require.NoError(t, hc.Restore(c, dgraphtest.DefaultBackupDir, "", incrFrom, i))
require.NoError(t, dgraphtest.WaitForRestore(c))
require.NoError(t, dgraphapi.WaitForRestore(c))
query := `{
vector(func: has(project_discription_v)) {
count(uid)
Expand Down Expand Up @@ -120,18 +121,18 @@ func TestVectorBackupRestore(t *testing.T) {
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.SetupSchema(testSchema))

numVectors := 1000
pred := "project_discription_v"
rdfs, vectors := dgraphtest.GenerateRandomVectors(0, numVectors, 10, pred)
rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 10, pred)

mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
_, err = gc.Mutate(mu)
Expand All @@ -142,7 +143,7 @@ func TestVectorBackupRestore(t *testing.T) {

t.Log("restoring backup \n")
require.NoError(t, hc.Restore(c, dgraphtest.DefaultBackupDir, "", 0, 0))
require.NoError(t, dgraphtest.WaitForRestore(c))
require.NoError(t, dgraphapi.WaitForRestore(c))

testVectorQuery(t, gc, vectors, rdfs, pred, numVectors)
}
Expand All @@ -159,19 +160,19 @@ func TestVectorBackupRestoreDropIndex(t *testing.T) {
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

// add vector predicate + index
require.NoError(t, gc.SetupSchema(testSchema))
// add data to the vector predicate
numVectors := 3
pred := "project_discription_v"
rdfs, vectors := dgraphtest.GenerateRandomVectors(0, numVectors, 1, pred)
rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 1, pred)
mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
_, err = gc.Mutate(mu)
require.NoError(t, err)
Expand All @@ -183,7 +184,7 @@ func TestVectorBackupRestoreDropIndex(t *testing.T) {
require.NoError(t, gc.SetupSchema(testSchemaWithoutIndex))

// add more data to the vector predicate
rdfs, vectors2 := dgraphtest.GenerateRandomVectors(3, numVectors+3, 1, pred)
rdfs, vectors2 := dgraphapi.GenerateRandomVectors(3, numVectors+3, 1, pred)
mu = &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
_, err = gc.Mutate(mu)
require.NoError(t, err)
Expand Down Expand Up @@ -212,7 +213,7 @@ func TestVectorBackupRestoreDropIndex(t *testing.T) {
// restore backup
t.Log("restoring backup \n")
require.NoError(t, hc.Restore(c, dgraphtest.DefaultBackupDir, "", 0, 0))
require.NoError(t, dgraphtest.WaitForRestore(c))
require.NoError(t, dgraphapi.WaitForRestore(c))

query := ` {
vectors(func: has(project_discription_v)) {
Expand Down Expand Up @@ -247,18 +248,18 @@ func TestVectorBackupRestoreReIndexing(t *testing.T) {
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.SetupSchema(testSchema))

numVectors := 1000
pred := "project_discription_v"
rdfs, vectors := dgraphtest.GenerateRandomVectors(0, numVectors, 10, pred)
rdfs, vectors := dgraphapi.GenerateRandomVectors(0, numVectors, 10, pred)

mu := &api.Mutation{SetNquads: []byte(rdfs), CommitNow: true}
_, err = gc.Mutate(mu)
Expand All @@ -267,14 +268,14 @@ func TestVectorBackupRestoreReIndexing(t *testing.T) {
t.Log("taking backup \n")
require.NoError(t, hc.Backup(c, false, dgraphtest.DefaultBackupDir))

rdfs2, vectors2 := dgraphtest.GenerateRandomVectors(numVectors, numVectors+300, 10, pred)
rdfs2, vectors2 := dgraphapi.GenerateRandomVectors(numVectors, numVectors+300, 10, pred)

mu = &api.Mutation{SetNquads: []byte(rdfs2), CommitNow: true}
_, err = gc.Mutate(mu)
require.NoError(t, err)
t.Log("restoring backup \n")
require.NoError(t, hc.Restore(c, dgraphtest.DefaultBackupDir, "", 2, 1))
require.NoError(t, dgraphtest.WaitForRestore(c))
require.NoError(t, dgraphapi.WaitForRestore(c))

for i := 0; i < 5; i++ {
// drop index
Expand Down
6 changes: 3 additions & 3 deletions systest/vector/vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ func TestVectorIndexOnVectorPredWithoutData(t *testing.T) {
require.NoError(t, err)
defer cleanup()
require.NoError(t, gc.LoginIntoNamespace(context.Background(),
dgraphtest.DefaultUser, dgraphtest.DefaultPassword, x.GalaxyNamespace))
dgraphapi.DefaultUser, dgraphapi.DefaultPassword, x.GalaxyNamespace))

hc, err := c.HTTPClient()
require.NoError(t, err)
require.NoError(t, hc.LoginIntoNamespace(dgraphtest.DefaultUser,
dgraphtest.DefaultPassword, x.GalaxyNamespace))
require.NoError(t, hc.LoginIntoNamespace(dgraphapi.DefaultUser,
dgraphapi.DefaultPassword, x.GalaxyNamespace))

require.NoError(t, gc.SetupSchema(testSchema))
pred := "project_discription_v"
Expand Down

0 comments on commit 766ddf5

Please sign in to comment.