diff --git a/.github/workflows/ci-dgraph-core-tests.yml b/.github/workflows/ci-dgraph-core-tests.yml index 34aadaaff35..c0e23a88561 100644 --- a/.github/workflows/ci-dgraph-core-tests.yml +++ b/.github/workflows/ci-dgraph-core-tests.yml @@ -25,7 +25,7 @@ permissions: jobs: dgraph-core-tests: if: github.event.pull_request.draft == false - runs-on: warp-ubuntu-latest-x64-4x + runs-on: warp-ubuntu-latest-x64-16x timeout-minutes: 60 steps: - uses: actions/checkout@v5 diff --git a/acl/acl_curl_test.go b/acl/acl_curl_test.go index b9672cddae5..a96c1fa1900 100644 --- a/acl/acl_curl_test.go +++ b/acl/acl_curl_test.go @@ -49,7 +49,7 @@ func (asuite *AclTestSuite) TestCurlAuthorization() { return []string{"-H", fmt.Sprintf("X-Dgraph-AccessToken:%s", jwt), "--ipv4", "-H", "Content-Type: application/dql", - "-d", query, testutil.SockAddrHttp + "/query"} + "-d", query, testutil.GetSockAddrHttp() + "/query"} } testutil.VerifyCurlCmd(t, queryArgs(hc.AccessJwt), &testutil.CurlFailureConfig{ ShouldFail: false, @@ -60,7 +60,7 @@ func (asuite *AclTestSuite) TestCurlAuthorization() { "-H", "Content-Type: application/rdf", "-d", fmt.Sprintf(`{ set { _:a <%s> "string" . - }}`, predicateToWrite), testutil.SockAddrHttp + "/mutate"} + }}`, predicateToWrite), testutil.GetSockAddrHttp() + "/mutate"} } @@ -71,7 +71,7 @@ func (asuite *AclTestSuite) TestCurlAuthorization() { alterArgs := func(jwt string) []string { return []string{"-H", fmt.Sprintf("X-Dgraph-AccessToken:%s", jwt), - "-d", fmt.Sprintf(`%s: int .`, predicateToAlter), testutil.SockAddrHttp + "/alter"} + "-d", fmt.Sprintf(`%s: int .`, predicateToAlter), testutil.GetSockAddrHttp() + "/alter"} } testutil.VerifyCurlCmd(t, alterArgs(hc.AccessJwt), &testutil.CurlFailureConfig{ ShouldFail: true, diff --git a/check_upgrade/check_upgrade_test.go b/check_upgrade/check_upgrade_test.go index f5b2be5ab04..003d42e3acb 100644 --- a/check_upgrade/check_upgrade_test.go +++ b/check_upgrade/check_upgrade_test.go @@ -10,9 +10,11 @@ package checkupgrade import ( "context" "fmt" + "os" "os/exec" "path/filepath" "regexp" + "runtime" "testing" "time" @@ -26,6 +28,11 @@ import ( ) func TestCheckUpgrade(t *testing.T) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping live load-uids tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } conf := dgraphtest.NewClusterConfig().WithNumAlphas(1).WithNumZeros(1).WithReplicas(1). WithACL(time.Hour).WithVersion("57aa5c4ac") c, err := dgraphtest.NewLocalCluster(conf) diff --git a/dgraph/cmd/dgraphimport/import_test.go b/dgraph/cmd/dgraphimport/import_test.go index d26074e7f7d..29189f3195d 100644 --- a/dgraph/cmd/dgraphimport/import_test.go +++ b/dgraph/cmd/dgraphimport/import_test.go @@ -10,7 +10,9 @@ import ( "context" "encoding/json" "fmt" + "os" "path/filepath" + "runtime" "strconv" "strings" "testing" @@ -301,6 +303,10 @@ func runImportTest(t *testing.T, tt testcase) { // setupBulkCluster creates and configures a cluster for bulk loading data func setupBulkCluster(t *testing.T, numAlphas int, encrypted bool) (*dgraphtest.LocalCluster, string) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + t.Skip("Skipping test on non-Linux platforms due to dgraph binary dependency") + } baseDir := t.TempDir() bulkConf := dgraphtest.NewClusterConfig(). WithNumAlphas(numAlphas). diff --git a/dgraph/cmd/increment/increment_test.go b/dgraph/cmd/increment/increment_test.go index 010e578950d..25e867708ca 100644 --- a/dgraph/cmd/increment/increment_test.go +++ b/dgraph/cmd/increment/increment_test.go @@ -124,7 +124,7 @@ func readBestEffort(t *testing.T, dg *dgo.Dgraph, pred string, M int) { } func setup(t *testing.T) *dgo.Dgraph { - dg, err := testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err := testutil.DgraphClientWithGroot(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } diff --git a/dgraph/cmd/live/load-json/load_test.go b/dgraph/cmd/live/load-json/load_test.go index 1dcecfcc098..0f114eca0b5 100644 --- a/dgraph/cmd/live/load-json/load_test.go +++ b/dgraph/cmd/live/load-json/load_test.go @@ -9,6 +9,7 @@ package live import ( "context" + "fmt" "os" "path/filepath" "runtime" @@ -22,7 +23,7 @@ import ( "github.com/hypermodeinc/dgraph/v25/x" ) -var alphaService = testutil.SockAddr +var alphaService = testutil.GetSockAddr() var ( testDataDir string @@ -161,11 +162,17 @@ func TestLiveLoadJSONMultipleFiles(t *testing.T) { } func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping live load-json tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + _, thisFile, _, _ := runtime.Caller(0) testDataDir = filepath.Dir(thisFile) var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) x.Panic(err) // Try to create any files in a dedicated temp directory that gets cleaned up diff --git a/dgraph/cmd/live/load-uids/load_test.go b/dgraph/cmd/live/load-uids/load_test.go index 86bc9483d5b..9d41cb59fe1 100644 --- a/dgraph/cmd/live/load-uids/load_test.go +++ b/dgraph/cmd/live/load-uids/load_test.go @@ -251,7 +251,7 @@ func TestLiveLoadExportedSchema(t *testing.T) { } }`, } - token := testutil.GrootHttpLogin("http://" + testutil.SockAddrHttp + "/admin") + token := testutil.GrootHttpLogin("http://" + testutil.GetSockAddrHttp() + "/admin") resp := testutil.MakeGQLRequestWithAccessJwt(t, params, token.AccessJwt) require.Nilf(t, resp.Errors, resp.Errors.Error()) @@ -351,8 +351,14 @@ func TestLiveLoadFileNameMultipleCorrect(t *testing.T) { } func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping live load-uids tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + + alphaService = testutil.GetSockAddr() alphaName = testutil.Instance - alphaService = testutil.SockAddr x.AssertTrue(strings.Count(alphaName, "_") == 2) left := strings.Index(alphaName, "_") @@ -365,7 +371,7 @@ func TestMain(m *testing.M) { fmt.Printf("Using test data dir: %s\n", testDataDir) var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) if err != nil { log.Fatalf("Error while getting a dgraph client: %v", err) } diff --git a/dgraph/cmd/version/version_test.go b/dgraph/cmd/version/version_test.go index 64aade7d549..b03fe08b597 100644 --- a/dgraph/cmd/version/version_test.go +++ b/dgraph/cmd/version/version_test.go @@ -6,8 +6,10 @@ package version import ( + "fmt" "os" "path/filepath" + "runtime" "testing" "github.com/stretchr/testify/require" @@ -16,6 +18,15 @@ import ( ) // Test `dgraph version` with an empty config file. +func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping version tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + m.Run() +} + func TestDgraphVersion(t *testing.T) { tmpPath := t.TempDir() configPath := filepath.Join(tmpPath, "config.yml") diff --git a/dgraph/cmd/zero/zero_test.go b/dgraph/cmd/zero/zero_test.go index 9ff8be69eaf..45ee4b9996a 100644 --- a/dgraph/cmd/zero/zero_test.go +++ b/dgraph/cmd/zero/zero_test.go @@ -41,7 +41,7 @@ func TestRemoveNode(t *testing.T) { func TestIdLeaseOverflow(t *testing.T) { dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} - con, err := grpc.NewClient(testutil.SockAddrZero, dialOpts...) + con, err := grpc.NewClient(testutil.GetSockAddrZero(), dialOpts...) require.NoError(t, err) zc := pb.NewZeroClient(con) @@ -55,7 +55,7 @@ func TestIdLeaseOverflow(t *testing.T) { func TestIdBump(t *testing.T) { dialOpts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} - con, err := grpc.NewClient(testutil.SockAddrZero, dialOpts...) + con, err := grpc.NewClient(testutil.GetSockAddrZero(), dialOpts...) require.NoError(t, err) zc := pb.NewZeroClient(con) diff --git a/dgraph/docker-compose.yml b/dgraph/docker-compose.yml index 6e2900264cd..bdeea04054f 100644 --- a/dgraph/docker-compose.yml +++ b/dgraph/docker-compose.yml @@ -11,7 +11,7 @@ services: service: zero volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true command: @@ -32,7 +32,7 @@ services: service: zero volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true command: @@ -52,7 +52,7 @@ services: service: zero volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true command: @@ -64,7 +64,7 @@ services: working_dir: /data/alpha1 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind @@ -95,7 +95,7 @@ services: - alpha1 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind @@ -126,7 +126,7 @@ services: - alpha2 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind @@ -157,7 +157,7 @@ services: - alpha3 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind @@ -188,7 +188,7 @@ services: - alpha4 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind @@ -219,7 +219,7 @@ services: - alpha5 volumes: - type: bind - source: $GOPATH/bin + source: ${GOPATH:?GOPATH environment variable is required but not set}/bin target: /gobin read_only: true - type: bind diff --git a/dgraphtest/compose_cluster.go b/dgraphtest/compose_cluster.go index 75bd7888c77..14129df6000 100644 --- a/dgraphtest/compose_cluster.go +++ b/dgraphtest/compose_cluster.go @@ -21,7 +21,7 @@ func NewComposeCluster() *ComposeCluster { } func (c *ComposeCluster) Client() (*dgraphapi.GrpcClient, func(), error) { - dg, err := dgo.NewClient(testutil.SockAddr, + dg, err := dgo.NewClient(testutil.GetSockAddr(), dgo.WithGrpcOption(grpc.WithTransportCredentials(insecure.NewCredentials()))) if err != nil { return nil, nil, err @@ -31,7 +31,7 @@ func (c *ComposeCluster) Client() (*dgraphapi.GrpcClient, func(), error) { // HTTPClient creates an HTTP client func (c *ComposeCluster) HTTPClient() (*dgraphapi.HTTPClient, error) { - httpClient, err := dgraphapi.GetHttpClient(testutil.SockAddrHttp, testutil.SockAddrZeroHttp) + httpClient, err := dgraphapi.GetHttpClient(testutil.GetSockAddrHttp(), testutil.GetSockAddrZeroHttp()) if err != nil { return nil, err } diff --git a/dgraphtest/local_cluster.go b/dgraphtest/local_cluster.go index 93715588a00..d40bffc7ec7 100644 --- a/dgraphtest/local_cluster.go +++ b/dgraphtest/local_cluster.go @@ -545,7 +545,7 @@ func (c *LocalCluster) containerHealthCheck(url func(c *LocalCluster) (string, e return errors.Wrapf(err, "error getting health URL %v", endpoint) } - for range 60 { + for attempt := range 60 { time.Sleep(waitDurBeforeRetry) endpoint, err = url(c) @@ -555,12 +555,16 @@ func (c *LocalCluster) containerHealthCheck(url func(c *LocalCluster) (string, e req, err := http.NewRequest(http.MethodGet, endpoint, nil) if err != nil { - log.Printf("[WARNING] error building req for endpoint [%v], err: [%v]", endpoint, err) + if attempt > 10 { + log.Printf("[WARNING] error building req for endpoint [%v], err: [%v]", endpoint, err) + } continue } body, err := dgraphapi.DoReq(req) if err != nil { - log.Printf("[WARNING] error hitting health endpoint [%v], err: [%v]", endpoint, err) + if attempt > 10 { + log.Printf("[WARNING] error hitting health endpoint [%v], err: [%v]", endpoint, err) + } continue } resp := string(body) @@ -602,13 +606,15 @@ func (c *LocalCluster) waitUntilLogin() error { ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) defer cancel() - for range 10 { + for attempt := range 10 { err := client.Login(ctx, dgraphapi.DefaultUser, dgraphapi.DefaultPassword) if err == nil { log.Printf("[INFO] login succeeded") return nil } - log.Printf("[WARNING] error trying to login: %v", err) + if attempt > 10 { + log.Printf("[WARNING] error trying to login: %v", err) + } time.Sleep(waitDurBeforeRetry) } return errors.New("error during login") diff --git a/graphql/e2e/schema/schema_test.go b/graphql/e2e/schema/schema_test.go index e303e3e7f09..550a6821c40 100644 --- a/graphql/e2e/schema/schema_test.go +++ b/graphql/e2e/schema/schema_test.go @@ -34,7 +34,7 @@ var ( groupOneHTTP = testutil.ContainerAddr("alpha1", 8080) groupTwoHTTP = testutil.ContainerAddr("alpha2", 8080) groupThreeHTTP = testutil.ContainerAddr("alpha3", 8080) - groupOnegRPC = testutil.SockAddr + groupOnegRPC = testutil.GetSockAddr() groupOneGraphQLServer = "http://" + groupOneHTTP + "/graphql" groupTwoGraphQLServer = "http://" + groupTwoHTTP + "/graphql" @@ -681,7 +681,7 @@ func TestDeleteSchemaAndExport(t *testing.T) { require.Equal(t, "Success", testutil.JsonGet(data, "export", "response", "code").(string)) taskId := testutil.JsonGet(data, "export", "taskId").(string) - testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, false, testutil.GetSockAddrHttp()) // applying a new schema should still work newSchemaResp := common.AssertUpdateGQLSchemaSuccess(t, groupOneHTTP, schema, nil) diff --git a/query/common_test.go b/query/common_test.go index 57c12618643..b3f7d538c01 100644 --- a/query/common_test.go +++ b/query/common_test.go @@ -350,7 +350,7 @@ type DispatchBoardCard { ` -const ngramVersionHash = "5d9fd2ed444b9ca1d3b03e7a51f5f92fc407cbaa" +const ngramVersionHash = "d7dfe3b4282fa3543e811c5538f86d39268961ba" func populateCluster(dc dgraphapi.Cluster) { x.Panic(client.Alter(context.Background(), &api.Operation{DropAll: true})) diff --git a/systest/1million/1million_test.go b/systest/1million/1million_test.go index 5bf2c4c3421..2a4965e5d81 100644 --- a/systest/1million/1million_test.go +++ b/systest/1million/1million_test.go @@ -12,6 +12,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "testing" "time" @@ -43,6 +44,11 @@ func Test1Million(t *testing.T) { } func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping 1million tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } noschemaFile := filepath.Join(testutil.TestDataDirectory, "1million-noindex.schema") rdfFile := filepath.Join(testutil.TestDataDirectory, "1million.rdf.gz") if err := testutil.MakeDirEmpty([]string{"out/0", "out/1", "out/2"}); err != nil { @@ -50,7 +56,7 @@ func TestMain(m *testing.M) { } if err := testutil.BulkLoad(testutil.BulkOpts{ - Zero: testutil.SockAddrZero, + Zero: testutil.GetSockAddrZero(), Shards: 1, RdfFile: rdfFile, SchemaFile: noschemaFile, diff --git a/systest/21million/bulk/run_test.go b/systest/21million/bulk/run_test.go index 826c7b417fa..1e918208c75 100644 --- a/systest/21million/bulk/run_test.go +++ b/systest/21million/bulk/run_test.go @@ -69,6 +69,11 @@ func BenchmarkQueries(b *testing.B) { } func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping 21million bulk tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } 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 { @@ -76,7 +81,7 @@ func TestMain(m *testing.M) { } if err := testutil.BulkLoad(testutil.BulkOpts{ - Zero: testutil.SockAddrZero, + Zero: testutil.GetSockAddrZero(), Shards: 1, RdfFile: rdfFile, SchemaFile: schemaFile, diff --git a/systest/acl/restore/acl_restore_test.go b/systest/acl/restore/acl_restore_test.go index 1ce94fea31f..eb373d7745f 100644 --- a/systest/acl/restore/acl_restore_test.go +++ b/systest/acl/restore/acl_restore_test.go @@ -101,7 +101,7 @@ func TestAclCacheRestore(t *testing.T) { dg := gc.Dgraph sendRestoreRequest(t, "/backups", "vibrant_euclid5", 1) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) token, err := testutil.Login(t, &testutil.LoginParams{UserID: "alice1", Passwd: "password", Namespace: 0}) diff --git a/systest/audit/audit_test.go b/systest/audit/audit_test.go index 512c1443a51..c9eaf7608a0 100644 --- a/systest/audit/audit_test.go +++ b/systest/audit/audit_test.go @@ -26,11 +26,11 @@ func TestZeroAudit(t *testing.T) { defer os.RemoveAll(fmt.Sprintf("audit_dir/za/zero_audit_0_%s.log", nId)) zeroCmd := map[string][]string{ "/removeNode": {`--location`, "--request", "GET", "--ipv4", - fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.GetSockAddrZeroHttp())}, "/assign": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/assign?what=uids&num=100", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/assign?what=uids&num=100", testutil.GetSockAddrZeroHttp())}, "/moveTablet": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.SockAddrZeroHttp)}} + fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.GetSockAddrZeroHttp())}} msgs := make([]string, 0) // logger is buffered. make calls in bunch so that dont want to wait for flush @@ -58,21 +58,21 @@ func TestAlphaAudit(t *testing.T) { defer os.Remove(fmt.Sprintf("audit_dir/aa/alpha_audit_1_%s.log", nId)) testCommand := map[string][]string{ "/admin": {"--location", "--request", "POST", "--ipv4", - fmt.Sprintf("%s/admin", testutil.SockAddrHttp), + fmt.Sprintf("%s/admin", testutil.GetSockAddrHttp()), "--header", "Content-Type: application/json", "--data-raw", `'{"query":"mutation {\n backup( input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response {\n message\n code\n }\n }\n}\n","variables":{}}'`}, //nolint:lll - "/graphql": {"--location", "--request", "POST", "--ipv4", fmt.Sprintf("%s/graphql", testutil.SockAddrHttp), + "/graphql": {"--location", "--request", "POST", "--ipv4", fmt.Sprintf("%s/graphql", testutil.GetSockAddrHttp()), "--header", "Content-Type: application/json", "--data-raw", `'{"query":"query {\n __schema {\n __typename\n }\n}","variables":{}}'`}, - "/alter": {"-X", "POST", "--ipv4", fmt.Sprintf("%s/alter", testutil.SockAddrHttp), "-d", + "/alter": {"-X", "POST", "--ipv4", fmt.Sprintf("%s/alter", testutil.GetSockAddrHttp()), "-d", `name: string @index(term) . type Person { name }`}, - "/query": {"-H", "'Content-Type: application/dql'", "-X", "POST", "--ipv4", fmt.Sprintf("%s/query", testutil.SockAddrHttp), + "/query": {"-H", "'Content-Type: application/dql'", "-X", "POST", "--ipv4", fmt.Sprintf("%s/query", testutil.GetSockAddrHttp()), "-d", `$' { balances(func: anyofterms(name, "Alice Bob")) { @@ -82,7 +82,7 @@ input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response { } }'`}, "/mutate": {"-H", "'Content-Type: application/rdf'", "-X", - "POST", "--ipv4", fmt.Sprintf("%s/mutate?startTs=4", testutil.SockAddrHttp), "-d", `$' + "POST", "--ipv4", fmt.Sprintf("%s/mutate?startTs=4", testutil.GetSockAddrHttp()), "-d", `$' { set { <0x1> "110" . diff --git a/systest/audit_encrypted/audit_test.go b/systest/audit_encrypted/audit_test.go index 45fcc3d6239..115c9b78152 100644 --- a/systest/audit_encrypted/audit_test.go +++ b/systest/audit_encrypted/audit_test.go @@ -11,6 +11,7 @@ import ( "fmt" "os" "os/exec" + "runtime" "testing" "github.com/stretchr/testify/require" @@ -19,6 +20,15 @@ import ( "github.com/hypermodeinc/dgraph/v25/testutil/testaudit" ) +func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping audit_encrypted tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + m.Run() +} + func TestZeroAuditEncrypted(t *testing.T) { state, err := testutil.GetState() require.NoError(t, err) @@ -27,11 +37,11 @@ func TestZeroAuditEncrypted(t *testing.T) { defer os.RemoveAll(fmt.Sprintf("audit_dir/za/zero_audit_0_%s.log.enc", nId)) zeroCmd := map[string][]string{ "/removeNode": {`--location`, "--request", "GET", "--ipv4", - fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.GetSockAddrZeroHttp())}, "/assign": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/assign?what=uids&num=100", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/assign?what=uids&num=100", testutil.GetSockAddrZeroHttp())}, "/moveTablet": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.SockAddrZeroHttp)}} + fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.GetSockAddrZeroHttp())}} msgs := make([]string, 0) // logger is buffered. make calls in bunch so that dont want to wait for flush @@ -77,21 +87,21 @@ func TestAlphaAuditEncrypted(t *testing.T) { defer os.Remove(fmt.Sprintf("audit_dir/aa/alpha_audit_1_%s.log.enc", nId)) testCommand := map[string][]string{ "/admin": {"--location", "--request", "POST", "--ipv4", - fmt.Sprintf("%s/admin", testutil.SockAddrHttp), + fmt.Sprintf("%s/admin", testutil.GetSockAddrHttp()), "--header", "Content-Type: application/json", "--data-raw", `'{"query":"mutation {\n backup( input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response {\n message\n code\n }\n }\n}\n","variables":{}}'`}, //nolint:lll - "/graphql": {"--location", "--request", "POST", "--ipv4", fmt.Sprintf("%s/graphql", testutil.SockAddrHttp), + "/graphql": {"--location", "--request", "POST", "--ipv4", fmt.Sprintf("%s/graphql", testutil.GetSockAddrHttp()), "--header", "Content-Type: application/json", "--data-raw", `'{"query":"query {\n __schema {\n __typename\n }\n}","variables":{}}'`}, - "/alter": {"-X", "POST", "--ipv4", fmt.Sprintf("%s/alter", testutil.SockAddrHttp), "-d", + "/alter": {"-X", "POST", "--ipv4", fmt.Sprintf("%s/alter", testutil.GetSockAddrHttp()), "-d", `name: string @index(term) . type Person { name }`}, - "/query": {"-H", "'Content-Type: application/dql'", "--ipv4", "-X", "POST", fmt.Sprintf("%s/query", testutil.SockAddrHttp), + "/query": {"-H", "'Content-Type: application/dql'", "--ipv4", "-X", "POST", fmt.Sprintf("%s/query", testutil.GetSockAddrHttp()), "-d", `$' { balances(func: anyofterms(name, "Alice Bob")) { @@ -101,7 +111,7 @@ input: {destination: \"/Users/sankalanparajuli/work/backup\"}) {\n response { } }'`}, "/mutate": {"-H", "'Content-Type: application/rdf'", "--ipv4", "-X", - "POST", fmt.Sprintf("%s/mutate?startTs=4", testutil.SockAddrHttp), "-d", `$' + "POST", fmt.Sprintf("%s/mutate?startTs=4", testutil.GetSockAddrHttp()), "-d", `$' { set { <0x1> "110" . diff --git a/systest/backup/encryption/backup_test.go b/systest/backup/encryption/backup_test.go index abf969b3112..a49f6c1dc71 100644 --- a/systest/backup/encryption/backup_test.go +++ b/systest/backup/encryption/backup_test.go @@ -55,7 +55,7 @@ func TestBackupMinioE(t *testing.T) { // internal-port true)) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddr, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddr(), conf) require.NoError(t, err) mc, err = testutil.NewMinioClient() require.NoError(t, err) @@ -87,7 +87,7 @@ func TestBackupMinioE(t *testing.T) { client := testutil.GetHttpsClient(t) tabletName := x.NamespaceAttr(x.RootNamespace, "movie") // Move tablet to group 1 to avoid messes later. - _, err = client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=movie&group=1") + _, err = client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=movie&group=1") require.NoError(t, err) // After the move, we need to pause a bit to give zero a chance to quorum. @@ -259,7 +259,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, } }` - adminUrl := "https://" + testutil.SockAddrHttp + "/admin" + adminUrl := "https://" + testutil.GetSockAddrHttp() + "/admin" params := testutil.GraphQLParams{ Query: backupRequest, Variables: map[string]interface{}{ @@ -278,7 +278,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, require.NoError(t, json.NewDecoder(resp.Body).Decode(&data)) require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string) - testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, true, testutil.GetSockAddrHttp()) // Verify that the right amount of files and directories were created. copyToLocalFs(t) diff --git a/systest/backup/filesystem/backup_test.go b/systest/backup/filesystem/backup_test.go index b647d7608e4..cb6f3d7a5b1 100644 --- a/systest/backup/filesystem/backup_test.go +++ b/systest/backup/filesystem/backup_test.go @@ -77,7 +77,7 @@ func TestBackupOfOldRestore(t *testing.T) { common.DirSetup(t) common.CopyOldBackupDir(t) - conn, err := grpc.NewClient(testutil.SockAddr, grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) require.NoError(t, err) @@ -88,7 +88,7 @@ func TestBackupOfOldRestore(t *testing.T) { _ = runBackup(t, 3, 1) sendRestoreRequest(t, oldBackupDir1) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) q := `{ authors(func: has(Author.name)) { count(uid) } }` resp, err := dg.NewTxn().Query(context.Background(), q) @@ -101,7 +101,7 @@ func TestBackupOfOldRestore(t *testing.T) { testutil.DropAll(t, dg) time.Sleep(2 * time.Second) sendRestoreRequest(t, alphaBackupDir) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) resp, err = dg.NewTxn().Query(context.Background(), q) require.NoError(t, err) @@ -118,7 +118,7 @@ func TestRestoreOfOldBackup(t *testing.T) { common.DirSetup(t) common.CopyOldBackupDir(t) - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -128,7 +128,7 @@ func TestRestoreOfOldBackup(t *testing.T) { time.Sleep(2 * time.Second) sendRestoreRequest(t, dir) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) queryAndCheck := func(pred string, cnt int) { q := fmt.Sprintf(`{ me(func: has(%s)) { count(uid) } }`, pred) @@ -148,7 +148,7 @@ func TestRestoreOfOldBackup(t *testing.T) { } func TestBackupFilesystem(t *testing.T) { - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -190,7 +190,7 @@ func TestBackupFilesystem(t *testing.T) { // Move tablet to group 1 to avoid messes later. client := testutil.GetHttpsClient(t) - _, err = client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=movie&group=1") + _, err = client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=movie&group=1") require.NoError(t, err) // After the move, we need to pause a bit to give zero a chance to quorum. @@ -403,7 +403,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, } }` - adminUrl := "https://" + testutil.SockAddrHttp + "/admin" + adminUrl := "https://" + testutil.GetSockAddrHttp() + "/admin" params := testutil.GraphQLParams{ Query: backupRequest, Variables: map[string]interface{}{ @@ -424,7 +424,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string) - testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, true, testutil.GetSockAddrHttp()) // Verify that the right amount of files and directories were created. common.CopyToLocalFs(t) diff --git a/systest/backup/minio-large/backup_test.go b/systest/backup/minio-large/backup_test.go index 53fb10d5b8e..8f58194b26e 100644 --- a/systest/backup/minio-large/backup_test.go +++ b/systest/backup/minio-large/backup_test.go @@ -47,7 +47,7 @@ var ( // Test to add a large database and verify backup and restore work as expected. func TestBackupMinioLarge(t *testing.T) { // backupDestination = "minio://" + testutil.DockerPrefix + "_minio_1:9001/dgraph-backup?secure=false" - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -89,13 +89,13 @@ func setupTablets(t *testing.T, dg *dgo.Dgraph) { name2: string . name3: string .`})) client := testutil.GetHttpsClient(t) - _, err := client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=name1&group=1") + _, err := client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=name1&group=1") require.NoError(t, err) time.Sleep(time.Second) - _, err = client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=name2&group=2") + _, err = client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=name2&group=2") require.NoError(t, err) time.Sleep(time.Second) - _, err = client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=name3&group=3") + _, err = client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=name3&group=3") require.NoError(t, err) // After the move, we need to pause a bit to give zero a chance to quorum. @@ -145,7 +145,7 @@ func runBackup(t *testing.T) { } }` - adminUrl := "https://" + testutil.SockAddrHttp + "/admin" + adminUrl := "https://" + testutil.GetSockAddrHttp() + "/admin" params := testutil.GraphQLParams{ Query: backupRequest, Variables: map[string]interface{}{ @@ -165,7 +165,7 @@ func runBackup(t *testing.T) { require.NoError(t, json.NewDecoder(resp.Body).Decode(&data)) require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string) - testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, true, testutil.GetSockAddrHttp()) // Verify that the right amount of files and directories were created. copyToLocalFs(t) diff --git a/systest/backup/minio/backup_test.go b/systest/backup/minio/backup_test.go index b9ded1e9512..3abea1acf05 100644 --- a/systest/backup/minio/backup_test.go +++ b/systest/backup/minio/backup_test.go @@ -49,7 +49,7 @@ func TestBackupMinio(t *testing.T) { addr := testutil.ContainerAddr("minio", 9001) localBackupDst = "minio://" + addr + "/dgraph-backup?secure=false" - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -83,7 +83,7 @@ func TestBackupMinio(t *testing.T) { // Move tablet to group 1 to avoid messes later. client := testutil.GetHttpsClient(t) - _, err = client.Get("https://" + testutil.SockAddrZeroHttp + "/moveTablet?tablet=movie&group=1") + _, err = client.Get("https://" + testutil.GetSockAddrZeroHttp() + "/moveTablet?tablet=movie&group=1") require.NoError(t, err) // After the move, we need to pause a bit to give zero a chance to quorum. @@ -284,7 +284,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, } }` - adminUrl := "https://" + testutil.SockAddrHttp + "/admin" + adminUrl := "https://" + testutil.GetSockAddrHttp() + "/admin" params := testutil.GraphQLParams{ Query: backupRequest, Variables: map[string]interface{}{ @@ -304,7 +304,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles, require.NoError(t, json.NewDecoder(resp.Body).Decode(&data)) require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string) - testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, true, testutil.GetSockAddrHttp()) // Verify that the right amount of files and directories were created. copyToLocalFs(t) diff --git a/systest/backup/multi-tenancy/backup_test.go b/systest/backup/multi-tenancy/backup_test.go index 70ca6725620..58a35128662 100644 --- a/systest/backup/multi-tenancy/backup_test.go +++ b/systest/backup/multi-tenancy/backup_test.go @@ -95,7 +95,7 @@ func TestBackupMultiTenancy(t *testing.T) { _ = runBackup(t, galaxyToken, 3, 1) testutil.DropAll(t, dg) sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) query := `{ q(func: has(movie)) { count(uid) } }` expectedResponse := `{ "q": [{ "count": 5 }]}` @@ -109,7 +109,7 @@ func TestBackupMultiTenancy(t *testing.T) { _ = runBackup(t, galaxyToken, 6, 2) testutil.DropAll(t, dg) sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) testutil.VerifyQueryResponse(t, dg, query, expectedResponse) testutil.VerifyQueryResponse(t, dg1, query, expectedResponse) testutil.VerifyQueryResponse(t, dg2, query, `{ "q": [{ "count": 0 }]}`) @@ -120,7 +120,7 @@ func TestBackupMultiTenancy(t *testing.T) { _ = runBackup(t, galaxyToken, 9, 3) testutil.DropAll(t, dg) sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) query = `{ q(func: has(movie)) { count(uid) } }` expectedResponse = `{ "q": [{ "count": 5 }]}` testutil.VerifyQueryResponse(t, dg, query, expectedResponse) @@ -158,7 +158,7 @@ func runBackupInternal(t *testing.T, token *testutil.HttpToken, forceFull bool, require.NoError(t, json.Unmarshal(resp.Data, &data)) require.Equal(t, "Success", testutil.JsonGet(data, "backup", "response", "code").(string)) taskId := testutil.JsonGet(data, "backup", "taskId").(string) - testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, false, testutil.GetSockAddrHttp()) // Verify that the right amount of files and directories were created. common.CopyToLocalFs(t) diff --git a/systest/backup/nfs-backup/backup_test.go b/systest/backup/nfs-backup/backup_test.go index aad520de74f..1c18257302c 100644 --- a/systest/backup/nfs-backup/backup_test.go +++ b/systest/backup/nfs-backup/backup_test.go @@ -40,14 +40,14 @@ var ( func TestBackupHAClust(t *testing.T) { - backupRestoreTest(t, testutil.SockAddr, testutil.SockAddrAlpha4Http, - testutil.SockAddrZeroHttp, backupDstHA, testutil.SockAddrHttp) + backupRestoreTest(t, testutil.GetSockAddr(), testutil.GetSockAddrAlpha4Http(), + testutil.GetSockAddrZeroHttp(), backupDstHA, testutil.GetSockAddrHttp()) } func TestBackupNonHAClust(t *testing.T) { - backupRestoreTest(t, testutil.SockAddrAlpha7, testutil.SockAddrAlpha8Http, - testutil.SockAddrZero7Http, backupDstNonHA, testutil.SockAddrAlpha7Http) + backupRestoreTest(t, testutil.GetSockAddrAlpha7(), testutil.GetSockAddrAlpha8Http(), + testutil.GetSockAddrZero7Http(), backupDstNonHA, testutil.GetSockAddrAlpha7Http()) } func backupRestoreTest(t *testing.T, backupAlphaSocketAddr string, restoreAlphaAddr string, diff --git a/systest/bgindex/count_test.go b/systest/bgindex/count_test.go index 9da951fcf06..f38c7c0e183 100644 --- a/systest/bgindex/count_test.go +++ b/systest/bgindex/count_test.go @@ -40,7 +40,7 @@ func TestCountIndex(t *testing.T) { var dg *dgo.Dgraph err := x.RetryUntilSuccess(10, time.Second, func() error { var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) return err }) require.NoError(t, err) diff --git a/systest/bgindex/parallel_test.go b/systest/bgindex/parallel_test.go index 8aa50781376..8940e5a9f3c 100644 --- a/systest/bgindex/parallel_test.go +++ b/systest/bgindex/parallel_test.go @@ -56,7 +56,7 @@ func TestParallelIndexing(t *testing.T) { var dg *dgo.Dgraph err := x.RetryUntilSuccess(10, time.Second, func() error { var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) return err }) require.NoError(t, err) diff --git a/systest/bgindex/reverse_test.go b/systest/bgindex/reverse_test.go index 06c84789d94..9eff322478e 100644 --- a/systest/bgindex/reverse_test.go +++ b/systest/bgindex/reverse_test.go @@ -34,7 +34,7 @@ func TestReverseIndex(t *testing.T) { var dg *dgo.Dgraph err := x.RetryUntilSuccess(10, time.Second, func() error { var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) return err }) require.NoError(t, err) diff --git a/systest/bgindex/string_test.go b/systest/bgindex/string_test.go index d2e0d0f6cfd..cfa2a73d0ca 100644 --- a/systest/bgindex/string_test.go +++ b/systest/bgindex/string_test.go @@ -39,7 +39,7 @@ func TestStringIndex(t *testing.T) { var dg *dgo.Dgraph err := x.RetryUntilSuccess(10, time.Second, func() error { var err error - dg, err = testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err = testutil.DgraphClientWithGroot(testutil.GetSockAddr()) return err }) require.NoError(t, err) diff --git a/systest/cdc/cdc_test.go b/systest/cdc/cdc_test.go index a12e3c1f2ec..045829d40ee 100644 --- a/systest/cdc/cdc_test.go +++ b/systest/cdc/cdc_test.go @@ -14,6 +14,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "testing" "time" @@ -23,9 +24,14 @@ import ( ) func TestCDC(t *testing.T) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + t.Skip("Skipping test on non-Linux platforms due to dgraph binary dependency") + } defer os.RemoveAll("./cdc_logs/sink.log") - cmd := exec.Command("dgraph", "increment", "--num", "10", - "--alpha", testutil.SockAddr) + path := testutil.DgraphBinaryPath() + cmd := exec.Command(path, "increment", "--num", "10", + "--alpha", testutil.GetSockAddr()) if out, err := cmd.CombinedOutput(); err != nil { fmt.Println(string(out)) t.Fatal(err) diff --git a/systest/export/export_test.go b/systest/export/export_test.go index fac50294f2d..ce200757f1c 100644 --- a/systest/export/export_test.go +++ b/systest/export/export_test.go @@ -12,10 +12,12 @@ import ( "compress/gzip" "context" "encoding/json" + "fmt" "io" "net/http" "os" "path/filepath" + "runtime" "strings" "testing" @@ -29,6 +31,15 @@ import ( "github.com/hypermodeinc/dgraph/v25/testutil" ) +func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping export tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + m.Run() +} + var ( bucketName = "dgraph-backup" minioDest = "minio://minio:9001/dgraph-backup?secure=false" @@ -120,7 +131,7 @@ func TestExportAndLoadJson(t *testing.T) { require.JSONEq(t, `{"data":{"q":[{"count": 5}]}}`, res) // Drop all data - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) require.NoError(t, err) require.NoError(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) @@ -201,7 +212,7 @@ func TestExportAndLoadJsonFacets(t *testing.T) { checkRes() // Drop all data - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) require.NoError(t, err) require.NoError(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) @@ -222,7 +233,7 @@ func TestExportAndLoadJsonFacets(t *testing.T) { } func runQuery(t *testing.T, q string) string { - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) require.NoError(t, err) resp, err := testutil.RetryQuery(dg, q) @@ -248,7 +259,7 @@ func loadData(t *testing.T, dir, format string) { pipeline := [][]string{ {testutil.DgraphBinaryPath(), "live", "-s", schemaFile, "-f", dataFile, "--alpha", - testutil.SockAddr, "--zero", testutil.SockAddrZero, + testutil.GetSockAddr(), "--zero", testutil.GetSockAddrZero(), }, } _, err := testutil.Pipeline(pipeline) @@ -266,7 +277,7 @@ func dirCleanup(t *testing.T) { func setupDgraph(t *testing.T, nquads, schema string) { require.NoError(t, os.MkdirAll("./data", os.ModePerm)) - conn, err := grpc.NewClient(testutil.SockAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -295,7 +306,7 @@ func requestExport(t *testing.T, dest string, format string) { } }` - adminUrl := "http://" + testutil.SockAddrHttp + "/admin" + adminUrl := "http://" + testutil.GetSockAddrHttp() + "/admin" params := testutil.GraphQLParams{ Query: exportRequest, Variables: map[string]interface{}{ @@ -313,5 +324,5 @@ func requestExport(t *testing.T, dest string, format string) { require.NoError(t, json.NewDecoder(resp.Body).Decode(&data)) require.Equal(t, "Success", testutil.JsonGet(data, "data", "export", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "export", "taskId").(string) - testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, false, testutil.GetSockAddrHttp()) } diff --git a/systest/group-delete/group_delete_test.go b/systest/group-delete/group_delete_test.go index 9ac15e736e8..686cf77727d 100644 --- a/systest/group-delete/group_delete_test.go +++ b/systest/group-delete/group_delete_test.go @@ -175,7 +175,7 @@ func TestNodes(t *testing.T) { require.NoError(t, err) for pred := range state1.Groups["2"].Tablets { - moveUrl := fmt.Sprintf("http://"+testutil.SockAddrZeroHttp+"/moveTablet?tablet=%s&group=1", + moveUrl := fmt.Sprintf("http://"+testutil.GetSockAddrZeroHttp()+"/moveTablet?tablet=%s&group=1", url.QueryEscape(pred)) resp, err := http.Get(moveUrl) require.NoError(t, err) @@ -192,7 +192,7 @@ func TestNodes(t *testing.T) { groupNodes, err = testutil.GetNodesInGroup("2") require.NoError(t, err) - resp, err := http.Get("http://" + testutil.SockAddrZeroHttp + "/removeNode?group=2&id=" + + resp, err := http.Get("http://" + testutil.GetSockAddrZeroHttp() + "/removeNode?group=2&id=" + groupNodes[0]) require.NoError(t, err) require.NoError(t, getError(resp.Body)) diff --git a/systest/integration2/bulk_loader_test.go b/systest/integration2/bulk_loader_test.go index b6e8b855eed..d96cdba0bbb 100644 --- a/systest/integration2/bulk_loader_test.go +++ b/systest/integration2/bulk_loader_test.go @@ -8,8 +8,10 @@ package main import ( + "fmt" "os" "path/filepath" + "runtime" "testing" "time" @@ -63,6 +65,10 @@ const ( ) func TestBulkLoaderNoDqlSchema(t *testing.T) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + t.Skip("Skipping test on non-Linux platforms due to dgraph binary dependency") + } conf := dgraphtest.NewClusterConfig().WithNumAlphas(2).WithNumZeros(1). WithACL(time.Hour).WithReplicas(1).WithBulkLoadOutDir(t.TempDir()) c, err := dgraphtest.NewLocalCluster(conf) diff --git a/systest/ldbc/ldbc_test.go b/systest/ldbc/ldbc_test.go index 6a30c423150..386f820e38d 100644 --- a/systest/ldbc/ldbc_test.go +++ b/systest/ldbc/ldbc_test.go @@ -12,6 +12,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "testing" "time" @@ -71,6 +72,11 @@ func TestQueries(t *testing.T) { } func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping LDBC tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } noschemaFile := filepath.Join(testutil.TestDataDirectory, "ldbcTypes.schema") rdfFile := testutil.TestDataDirectory if err := testutil.MakeDirEmpty([]string{"out/0"}); err != nil { @@ -80,7 +86,7 @@ func TestMain(m *testing.M) { start := time.Now() fmt.Println("Bulkupload started") if err := testutil.BulkLoad(testutil.BulkOpts{ - Zero: testutil.SockAddrZero, + Zero: testutil.GetSockAddrZero(), Shards: 1, RdfFile: rdfFile, SchemaFile: noschemaFile, diff --git a/systest/live_pw_test.go b/systest/live_pw_test.go index e73796e3be9..6b3d32c20e3 100644 --- a/systest/live_pw_test.go +++ b/systest/live_pw_test.go @@ -22,7 +22,7 @@ import ( func TestLivePassword(t *testing.T) { wrap := func(fn func(*testing.T, *dgo.Dgraph)) func(*testing.T) { return func(t *testing.T) { - dg, err := testutil.DgraphClientWithGroot(testutil.SockAddr) + dg, err := testutil.DgraphClientWithGroot(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } diff --git a/systest/loader/loader_test.go b/systest/loader/loader_test.go index 100c401f91c..b1beb685e59 100644 --- a/systest/loader/loader_test.go +++ b/systest/loader/loader_test.go @@ -12,6 +12,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "testing" "github.com/spf13/viper" @@ -22,6 +23,15 @@ import ( "github.com/hypermodeinc/dgraph/v25/x" ) +func TestMain(m *testing.M) { + if runtime.GOOS != "linux" && os.Getenv("DGRAPH_BINARY") == "" { + fmt.Println("Skipping loader tests on non-Linux platforms due to dgraph binary dependency") + fmt.Println("You can set the DGRAPH_BINARY environment variable to path of a native dgraph binary to run these tests") + os.Exit(0) + } + m.Run() +} + // TestLoaderXidmap checks that live loader re-uses xidmap on loading data from two different files func TestLoaderXidmap(t *testing.T) { @@ -39,7 +49,7 @@ func TestLoaderXidmap(t *testing.T) { // internal-port true)) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddrLocalhost, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddrLocalhost(), conf) require.NoError(t, err) ctx := context.Background() testutil.DropAll(t, dg) @@ -67,8 +77,8 @@ func TestLoaderXidmap(t *testing.T) { err = testutil.ExecWithOpts([]string{testutil.DgraphBinaryPath(), "live", "--tls", tlsFlag, "--files", data, - "--alpha", testutil.SockAddrLocalhost, - "--zero", testutil.SockAddrZeroLocalhost, + "--alpha", testutil.GetSockAddrLocalhost(), + "--zero", testutil.GetSockAddrZeroLocalhost(), "-x", "x"}, testutil.CmdOpts{Dir: tmpDir}) require.NoError(t, err) @@ -78,8 +88,8 @@ func TestLoaderXidmap(t *testing.T) { err = testutil.ExecWithOpts([]string{testutil.DgraphBinaryPath(), "live", "--tls", tlsFlag, "--files", data, - "--alpha", testutil.SockAddrLocalhost, - "--zero", testutil.SockAddrZeroLocalhost, + "--alpha", testutil.GetSockAddrLocalhost(), + "--zero", testutil.GetSockAddrZeroLocalhost(), "-x", "x"}, testutil.CmdOpts{Dir: tmpDir}) require.NoError(t, err) diff --git a/systest/online-restore/online_restore_test.go b/systest/online-restore/online_restore_test.go index ee4a936672a..495d59fc38a 100644 --- a/systest/online-restore/online_restore_test.go +++ b/systest/online-restore/online_restore_test.go @@ -205,7 +205,7 @@ func runMutations(t *testing.T, dg *dgo.Dgraph) { func TestBasicRestore(t *testing.T) { disableDraining(t) - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -216,7 +216,7 @@ func TestBasicRestore(t *testing.T) { snapshotTs := getSnapshotTs(t) req := &restoreReq{location: backupLocation, backupId: "youthful_rhodes3", encKeyFile: encKeyFile} sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) // Snapshot must be taken just after the restore and hence the snapshotTs be updated. require.NoError(t, x.RetryUntilSuccess(3, 2*time.Second, func() error { @@ -244,7 +244,7 @@ func TestBasicRestore(t *testing.T) { // drop all // Take backup b6 func TestIncrementalRestore(t *testing.T) { - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -257,7 +257,7 @@ func TestIncrementalRestore(t *testing.T) { backupNum: 1, } sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) query := `{ q(func: has(name)) { name age } }` runQuery := func(query, expectedResp string) { @@ -273,7 +273,7 @@ func TestIncrementalRestore(t *testing.T) { incrementalFrom: 2, } sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQuery(query, `{"q":[{"name":"alice"}, {"name":"bob", "age": "12"}]}`) req = &restoreReq{ @@ -282,7 +282,7 @@ func TestIncrementalRestore(t *testing.T) { incrementalFrom: 3, } sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQuery(query, `{"q":[]}`) runQuery(`{ q(func: has(age)) {age} }`, `{"q":[{"age": "12"}]}`) @@ -292,7 +292,7 @@ func TestIncrementalRestore(t *testing.T) { incrementalFrom: 4, } sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQuery(query, `{"q":[{"name":"alice"}]}`) req = &restoreReq{ @@ -302,7 +302,7 @@ func TestIncrementalRestore(t *testing.T) { } sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQuery(query, `{"q":[]}`) runQuery(`{ q(func: has(age)) {age} }`, `{"q":[]}`) @@ -320,7 +320,7 @@ func TestIncrementalRestore(t *testing.T) { // after drop all sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQuery(query, `{"q":[]}`) runQuery(`{ q(func: has(age)) {age} }`, `{"q":[]}`) @@ -334,7 +334,7 @@ func TestRestoreBackupNum(t *testing.T) { disableDraining(t) conn, err := grpc.NewClient( - testutil.SockAddr, + testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t))), ) require.NoError(t, err) @@ -346,7 +346,7 @@ func TestRestoreBackupNum(t *testing.T) { req := &restoreReq{location: backupLocation, backupId: "youthful_rhodes3", backupNum: 1, encKeyFile: encKeyFile} sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQueries(t, dg, true) runMutations(t, dg) @@ -356,7 +356,7 @@ func TestRestoreBackupNumInvalid(t *testing.T) { disableDraining(t) conn, err := grpc.NewClient( - testutil.SockAddr, + testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t))), ) require.NoError(t, err) @@ -416,7 +416,7 @@ func TestMoveTablets(t *testing.T) { disableDraining(t) conn, err := grpc.NewClient( - testutil.SockAddr, + testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t))), ) require.NoError(t, err) @@ -427,14 +427,14 @@ func TestMoveTablets(t *testing.T) { req := &restoreReq{location: backupLocation, backupId: "youthful_rhodes3", encKeyFile: encKeyFile} sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) runQueries(t, dg, false) // Send another restore request with a different backup. This backup has some of the // same predicates as the previous one but they are stored in different groups. req = &restoreReq{location: backupLocation, backupId: "blissful_hermann1", encKeyFile: encKeyFile} sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) resp, err := dg.NewTxn().Query(context.Background(), `{ q(func: has(name), orderasc: name) { @@ -514,7 +514,7 @@ func TestListBackups(t *testing.T) { } func TestRestoreWithDropOperations(t *testing.T) { - conn, err := grpc.NewClient(testutil.SockAddr, + conn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(testutil.GetAlphaClientConfig(t)))) require.NoError(t, err) dg := dgo.NewDgraphClient(api.NewDgraphClient(conn)) @@ -713,7 +713,7 @@ func backupRestoreAndVerify(t *testing.T, dg *dgo.Dgraph, backupDir, queryToVeri backup(t, backupDir) req := &restoreReq{location: backupDir, encKeyFile: encKeyFile} sendRestoreRequest(t, req) - testutil.WaitForRestore(t, dg, testutil.SockAddrHttp) + testutil.WaitForRestore(t, dg, testutil.GetSockAddrHttp()) testutil.VerifyQueryResponse(t, dg, queryToVerify, expectedResponse) testutil.VerifySchema(t, dg, schemaVerificationOpts) } diff --git a/t/t.go b/t/t.go index 6eebf61f93e..47bc7e427fd 100644 --- a/t/t.go +++ b/t/t.go @@ -41,6 +41,14 @@ import ( "github.com/hypermodeinc/dgraph/v25/x" ) +const ( + // Cluster configuration constants + NumZeroNodes = 3 + NumAlphaNodes = 6 + ZeroPort = 6080 + AlphaPort = 8080 +) + var ( ctxb = context.Background() oc = &outputCatcher{} @@ -163,6 +171,10 @@ func command(args ...string) *exec.Cmd { } func startCluster(composeFile, prefix string) error { + + if os.Getenv("GOPATH") == "" { + return fmt.Errorf("GOPATH environment variable is required but not set") + } cmd := command( "docker", "compose", "--compatibility", "-f", composeFile, "-p", prefix, "up", "--force-recreate", "--build", "--remove-orphans", "--detach") @@ -176,20 +188,35 @@ func startCluster(composeFile, prefix string) error { } fmt.Printf("CLUSTER UP: %s. Package: %s\n", prefix, composeFile) - // Wait for cluster to be healthy. - for i := 1; i <= 3; i++ { - in := testutil.GetContainerInstance(prefix, "zero"+strconv.Itoa(i)) - if err := in.BestEffortWaitForHealthy(6080); err != nil { - fmt.Printf("Error while checking zero health %s. Error %v", in.Name, err) - } + // Wait for cluster to be healthy using concurrent health checks + var wg sync.WaitGroup + // Check zero nodes health concurrently + for i := 1; i <= NumZeroNodes; i++ { + wg.Add(1) + go func(nodeNum int) { + defer wg.Done() + in := testutil.GetContainerInstance(prefix, "zero"+strconv.Itoa(nodeNum)) + if err := in.BestEffortWaitForHealthy(ZeroPort); err != nil { + fmt.Printf("Error while checking zero health %s. Error %v\n", in.Name, err) + } + }(i) } - for i := 1; i <= 6; i++ { - in := testutil.GetContainerInstance(prefix, "alpha"+strconv.Itoa(i)) - if err := in.BestEffortWaitForHealthy(8080); err != nil { - fmt.Printf("Error while checking alpha health %s. Error %v", in.Name, err) - } + + // Check alpha nodes health concurrently + for i := 1; i <= NumAlphaNodes; i++ { + wg.Add(1) + go func(nodeNum int) { + defer wg.Done() + in := testutil.GetContainerInstance(prefix, "alpha"+strconv.Itoa(nodeNum)) + if err := in.BestEffortWaitForHealthy(AlphaPort); err != nil { + fmt.Printf("Error while checking alpha health %s. Error %v\n", in.Name, err) + } + }(i) } + + // Wait for all health checks to complete + wg.Wait() return nil } @@ -447,15 +474,17 @@ func runTests(taskCh chan task, closer *z.Closer) error { prefix := getClusterPrefix() var started, stopped bool - start := func() { + start := func() error { if len(*useExisting) > 0 || started { - return + return nil } err := startCluster(defaultCompose, prefix) if err != nil { closer.Signal() + return err } started = true + return nil } stop := func() { @@ -508,7 +537,9 @@ func runTests(taskCh chan task, closer *z.Closer) error { // If we only need to run custom cluster tests, then skip this one. continue } - start() + if err := start(); err != nil { + return err + } if err = runTestsFor(ctx, task.pkg.ID, prefix, xmlFile); err != nil { // fmt.Printf("ERROR for package: %s. Err: %v\n", task.pkg.ID, err) return err diff --git a/testutil/client.go b/testutil/client.go index 92a135bb678..d09f32d108d 100644 --- a/testutil/client.go +++ b/testutil/client.go @@ -18,6 +18,7 @@ import ( "path/filepath" "runtime" "strings" + "sync" "testing" "time" @@ -43,84 +44,245 @@ var ( TestDataDirectory string Instance string MinioInstance string - // SockAddr is the address to the gRPC endpoint of the alpha used during tests with localhost - SockAddrLocalhost string - // SockAddr is the address to the gRPC endpoint of the alpha used during tests. - SockAddr string - // SockAddrHttp is the address to the HTTP of alpha used during tests. - SockAddrHttp string - SockAddrHttpLocalhost string - // SockAddrZero is the address to the gRPC endpoint of the zero used during tests. - SockAddrZero string - // SockAddrZeroHttp is the address to the HTTP endpoint of the zero used during tests. - SockAddrZeroHttp string - SockAddrZeroLocalhost string - - // SockAddrAlpha4 is the address to the gRPC endpoint of the alpha4 used during restore tests. - SockAddrAlpha4 string - // SockAddrAlpha4Http is the address to the HTTP of alpha4 used during restore tests. - SockAddrAlpha4Http string - // SockAddrZero4 is the address to the gRPC endpoint of the zero4 used during restore tests. - SockAddrZero4 string - // SockAddrZero4Http is the address to the HTTP endpoint of the zero4 used during restore tests. - SockAddrZero4Http string - // SockAddrAlpha7 is the address to the gRPC endpoint of the alpha4 used during restore tests. - SockAddrAlpha7 string - // SockAddrAlpha7Http is the address to the HTTP of alpha7 used during restore tests. - SockAddrAlpha7Http string - // SockAddrZero7 is the address to the gRPC endpoint of the zero7 used during restore tests. - SockAddrZero7 string - // SockAddrZero7Http is the address to the HTTP endpoint of the zero7 used during restore tests. - SockAddrZero7Http string - // SockAddrAlpha8 is the address to the gRPC endpoint of the alpha8 used during restore tests. - SockAddrAlpha8 string - // SockAddrAlpha8Http is the address to the HTTP of alpha8 used during restore tests. - SockAddrAlpha8Http string - // SockAddrZero8 is the address to the gRPC endpoint of the zero8 used during restore tests. - SockAddrZero8 string - // SockAddrZero8Http is the address to the HTTP endpoint of the zero8 used during restore tests. - SockAddrZero8Http string + + // sockAddrLocalhost is the address to the gRPC endpoint of the alpha used during tests with localhost + sockAddrLocalhost string + // sockAddr is the address to the gRPC endpoint of the alpha used during tests. + sockAddr string + // sockAddrHttp is the address to the HTTP of alpha used during tests. + sockAddrHttp string + sockAddrHttpLocalhost string + // sockAddrZero is the address to the gRPC endpoint of the zero used during tests. + sockAddrZero string + // sockAddrZeroHttp is the address to the HTTP endpoint of the zero used during tests. + sockAddrZeroHttp string + sockAddrZeroLocalhost string + + // sockAddrAlpha4 is the address to the gRPC endpoint of the alpha4 used during restore tests. + sockAddrAlpha4 string + // sockAddrAlpha4Http is the address to the HTTP of alpha4 used during restore tests. + sockAddrAlpha4Http string + // sockAddrZero4 is the address to the gRPC endpoint of the zero4 used during restore tests. + sockAddrZero4 string + // sockAddrZero4Http is the address to the HTTP endpoint of the zero4 used during restore tests. + sockAddrZero4Http string + // sockAddrAlpha7 is the address to the gRPC endpoint of the alpha4 used during restore tests. + sockAddrAlpha7 string + // sockAddrAlpha7Http is the address to the HTTP of alpha7 used during restore tests. + sockAddrAlpha7Http string + // sockAddrZero7 is the address to the gRPC endpoint of the zero7 used during restore tests. + sockAddrZero7 string + // sockAddrZero7Http is the address to the HTTP endpoint of the zero7 used during restore tests. + sockAddrZero7Http string + // sockAddrAlpha8 is the address to the gRPC endpoint of the alpha8 used during restore tests. + sockAddrAlpha8 string + // sockAddrAlpha8Http is the address to the HTTP of alpha8 used during restore tests. + sockAddrAlpha8Http string + // sockAddrZero8 is the address to the gRPC endpoint of the zero8 used during restore tests. + sockAddrZero8 string + // sockAddrZero8Http is the address to the HTTP endpoint of the zero8 used during restore tests. + sockAddrZero8Http string + + // sync.Once to ensure addresses are initialized only once + addressInitOnce sync.Once ) func AdminUrlHttps() string { - return "https://" + SockAddrHttp + "/admin" + ensureAddressesInitialized() + return "https://" + sockAddrHttp + "/admin" } func AdminUrl() string { - return "http://" + SockAddrHttp + "/admin" + ensureAddressesInitialized() + return "http://" + sockAddrHttp + "/admin" } -// This allows running (most) tests against dgraph running on the default ports, for example. -// Only the GRPC ports are needed and the others are deduced. +// Initialize basic environment variables that don't require Docker API calls func init() { DockerPrefix = os.Getenv("TEST_DOCKER_PREFIX") TestDataDirectory = os.Getenv("TEST_DATA_DIRECTORY") - MinioInstance = ContainerAddr("minio", 9001) - Instance = fmt.Sprintf("%s_%s_1", DockerPrefix, "alpha1") - SockAddrLocalhost = ContainerAddrLocalhost("alpha1", 9080) - SockAddr = ContainerAddr("alpha1", 9080) - SockAddrHttp = ContainerAddr("alpha1", 8080) - SockAddrHttpLocalhost = ContainerAddrLocalhost("alpha1", 8080) - - SockAddrZero = ContainerAddr("zero1", 5080) - SockAddrZeroLocalhost = ContainerAddrLocalhost("zero1", 5080) - SockAddrZeroHttp = ContainerAddr("zero1", 6080) - - SockAddrAlpha4 = ContainerAddr("alpha4", 9080) - SockAddrAlpha4Http = ContainerAddr("alpha4", 8080) - SockAddrAlpha7 = ContainerAddr("alpha7", 9080) - SockAddrAlpha7Http = ContainerAddr("alpha7", 8080) - SockAddrZero7 = ContainerAddr("zero7", 5080) - SockAddrZero7Http = ContainerAddr("zero7", 6080) - SockAddrAlpha8 = ContainerAddr("alpha8", 9080) - SockAddrAlpha8Http = ContainerAddr("alpha8", 8080) - SockAddrZero8 = ContainerAddr("zero8", 5080) - SockAddrZero8Http = ContainerAddr("zero8", 6080) - - SockAddrZero4 = ContainerAddr("zero2", 5080) - SockAddrZero4Http = ContainerAddr("zero2", 6080) - - fmt.Printf("testutil: %q %s %s\n", DockerPrefix, SockAddr, SockAddrZero) +} + +// ensureAddressesInitialized ensures that all address variables are populated +// This uses sync.Once to ensure thread-safe lazy initialization +func ensureAddressesInitialized() { + addressInitOnce.Do(func() { + if DockerPrefix == "" { + // Use default ports when no Docker containers are available + MinioInstance = "localhost:9001" + Instance = "alpha1_1" + sockAddrLocalhost = "localhost:9080" + sockAddr = "localhost:9080" + sockAddrHttp = "localhost:8080" + sockAddrHttpLocalhost = "localhost:8080" + + sockAddrZero = "localhost:5080" + sockAddrZeroLocalhost = "localhost:5080" + sockAddrZeroHttp = "localhost:6080" + sockAddrAlpha4 = "localhost:9080" + sockAddrAlpha4Http = "localhost:8080" + sockAddrAlpha7 = "localhost:9080" + sockAddrAlpha7Http = "localhost:8080" + sockAddrZero7 = "localhost:5080" + sockAddrZero7Http = "localhost:6080" + sockAddrAlpha8 = "localhost:9080" + sockAddrAlpha8Http = "localhost:8080" + sockAddrZero8 = "localhost:5080" + sockAddrZero8Http = "localhost:6080" + + sockAddrZero4 = "localhost:5080" + sockAddrZero4Http = "localhost:6080" + } else { + Instance = fmt.Sprintf("%s_%s_1", DockerPrefix, "alpha1") + + // Define container configurations for multi-threaded resolution + type containerConfig struct { + name string + port uint16 + target *string + useLocalhost bool + } + + // Configure all container address resolutions + configs := []containerConfig{ + {"minio", 9001, &MinioInstance, false}, + {"alpha1", 9080, &sockAddrLocalhost, true}, + {"alpha1", 9080, &sockAddr, false}, + {"alpha1", 8080, &sockAddrHttp, false}, + {"alpha1", 8080, &sockAddrHttpLocalhost, true}, + {"zero1", 5080, &sockAddrZero, false}, + {"zero1", 5080, &sockAddrZeroLocalhost, true}, + {"zero1", 6080, &sockAddrZeroHttp, false}, + {"alpha4", 9080, &sockAddrAlpha4, false}, + {"alpha4", 8080, &sockAddrAlpha4Http, false}, + {"alpha7", 9080, &sockAddrAlpha7, false}, + {"alpha7", 8080, &sockAddrAlpha7Http, false}, + {"zero7", 5080, &sockAddrZero7, false}, + {"zero7", 6080, &sockAddrZero7Http, false}, + {"alpha8", 9080, &sockAddrAlpha8, false}, + {"alpha8", 8080, &sockAddrAlpha8Http, false}, + {"zero8", 5080, &sockAddrZero8, false}, + {"zero8", 6080, &sockAddrZero8Http, false}, + {"zero2", 5080, &sockAddrZero4, false}, + {"zero2", 6080, &sockAddrZero4Http, false}, + } + + // Resolve addresses concurrently + var wg sync.WaitGroup + for _, config := range configs { + wg.Add(1) + go func(cfg containerConfig) { + defer wg.Done() + if cfg.useLocalhost { + *cfg.target = ContainerAddrLocalhost(cfg.name, cfg.port) + } else { + *cfg.target = ContainerAddr(cfg.name, cfg.port) + } + }(config) + } + + // Wait for all goroutines to complete + wg.Wait() + } + }) +} + +// Getter functions that ensure addresses are initialized before returning them +// These can be used when you need to ensure initialization happens + +func GetSockAddr() string { + ensureAddressesInitialized() + return sockAddr +} + +func GetSockAddrHttp() string { + ensureAddressesInitialized() + return sockAddrHttp +} + +func GetSockAddrZero() string { + ensureAddressesInitialized() + return sockAddrZero +} + +func GetSockAddrZeroHttp() string { + ensureAddressesInitialized() + return sockAddrZeroHttp +} + +func GetSockAddrLocalhost() string { + ensureAddressesInitialized() + return sockAddrLocalhost +} + +func GetSockAddrHttpLocalhost() string { + ensureAddressesInitialized() + return sockAddrHttpLocalhost +} + +func GetSockAddrZeroLocalhost() string { + ensureAddressesInitialized() + return sockAddrZeroLocalhost +} + +func GetSockAddrAlpha4() string { + ensureAddressesInitialized() + return sockAddrAlpha4 +} + +func GetSockAddrAlpha4Http() string { + ensureAddressesInitialized() + return sockAddrAlpha4Http +} + +func GetSockAddrZero4() string { + ensureAddressesInitialized() + return sockAddrZero4 +} + +func GetSockAddrZero4Http() string { + ensureAddressesInitialized() + return sockAddrZero4Http +} + +func GetSockAddrAlpha7() string { + ensureAddressesInitialized() + return sockAddrAlpha7 +} + +func GetSockAddrAlpha7Http() string { + ensureAddressesInitialized() + return sockAddrAlpha7Http +} + +func GetSockAddrZero7() string { + ensureAddressesInitialized() + return sockAddrZero7 +} + +func GetSockAddrZero7Http() string { + ensureAddressesInitialized() + return sockAddrZero7Http +} + +func GetSockAddrAlpha8() string { + ensureAddressesInitialized() + return sockAddrAlpha8 +} + +func GetSockAddrAlpha8Http() string { + ensureAddressesInitialized() + return sockAddrAlpha8Http +} + +func GetSockAddrZero8() string { + ensureAddressesInitialized() + return sockAddrZero8 +} + +func GetSockAddrZero8Http() string { + ensureAddressesInitialized() + return sockAddrZero8Http } // DgraphClientDropAll creates a Dgraph client and drops all existing data. @@ -487,7 +649,8 @@ top: // AssignUids talks to zero to assign the given number of uids. func AssignUids(num uint64) error { - resp, err := http.Get(fmt.Sprintf("http://"+SockAddrZeroHttp+"/assign?what=uids&num=%d", num)) + ensureAddressesInitialized() + resp, err := http.Get(fmt.Sprintf("http://"+sockAddrZeroHttp+"/assign?what=uids&num=%d", num)) type assignResp struct { Errors []struct { Message string diff --git a/testutil/docker.go b/testutil/docker.go index bd5aa9b5017..d948f58b5bb 100644 --- a/testutil/docker.go +++ b/testutil/docker.go @@ -68,7 +68,8 @@ func (in ContainerInstance) BestEffortWaitForHealthy(privatePort uint16) error { } tryWith := func(host string) error { - for range 60 { + maxAttempts := 60 + for attempt := range maxAttempts { resp, err := http.Get("http://" + host + ":" + port + "/health") var body []byte if resp != nil && resp.Body != nil { @@ -79,13 +80,17 @@ func (in ContainerInstance) BestEffortWaitForHealthy(privatePort uint16) error { if aerr := checkACL(body); aerr == nil { return nil } else { - fmt.Printf("waiting for login to work: %v\n", aerr) + if attempt > 10 { + fmt.Printf("waiting for login to work: %v\n", aerr) + } time.Sleep(time.Second) continue } } - fmt.Printf("Health for %s failed: %v. Response: %q. Retrying...\n", in, err, body) - time.Sleep(time.Second) + if attempt > 10 { + fmt.Printf("Health for %s failed: %v. Response: %q. Retrying...\n", in, err, body) + } + time.Sleep(500 * time.Millisecond) } return fmt.Errorf("did not pass health check on %s", "http://"+host+":"+port+"/health\n") } diff --git a/testutil/graphql.go b/testutil/graphql.go index 69d77d20c0c..47233508538 100644 --- a/testutil/graphql.go +++ b/testutil/graphql.go @@ -91,11 +91,12 @@ func MakeGQLRequestWithAccessJwt(t *testing.T, params *GraphQLParams, accessToke func MakeGQLRequestWithAccessJwtAndTLS(t *testing.T, params *GraphQLParams, tls *tls.Config, accessToken string) *GraphQLResponse { + ensureAddressesInitialized() var adminUrl string if tls != nil { - adminUrl = "https://" + SockAddrHttp + "/admin" + adminUrl = "https://" + GetSockAddrHttp() + "/admin" } else { - adminUrl = "http://" + SockAddrHttp + "/admin" + adminUrl = "http://" + GetSockAddrHttp() + "/admin" } b, err := json.Marshal(params) diff --git a/testutil/minio.go b/testutil/minio.go index 2ed6b7302fb..b40147a8c9b 100644 --- a/testutil/minio.go +++ b/testutil/minio.go @@ -6,14 +6,44 @@ package testutil import ( + "context" + "fmt" + "time" + "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" ) // NewMinioClient returns a minio client. func NewMinioClient() (*minio.Client, error) { - return minio.New(MinioInstance, &minio.Options{ + ensureAddressesInitialized() + if MinioInstance == "" { + return nil, fmt.Errorf("testutil.MinioInstance is not set") + } + + mc, err := minio.New(MinioInstance, &minio.Options{ Creds: credentials.NewStaticV4("accesskey", "secretkey", ""), Secure: false, }) + if err != nil { + return nil, err + } + + var errHealthCheck error + for i := 0; i < 5; i++ { + // Use a short timeout for the health check to avoid long waits. + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) + + // BucketExists is a lightweight call to check for connectivity. + // We don't care about the result, just that it doesn't error. + _, errHealthCheck = mc.BucketExists(ctx, "healthcheck") + if errHealthCheck == nil { + cancel() + return mc, nil + } + cancel() + time.Sleep(time.Second) + } + + return nil, fmt.Errorf("minio client not ready: %w", errHealthCheck) } diff --git a/testutil/multi_tenancy.go b/testutil/multi_tenancy.go index 6f160289197..6837cbcfcd4 100644 --- a/testutil/multi_tenancy.go +++ b/testutil/multi_tenancy.go @@ -339,7 +339,8 @@ func AddRulesToGroup(t *testing.T, token *HttpToken, group string, rules []Rule, } func DgClientWithLogin(t *testing.T, id, password string, ns uint64) *dgo.Dgraph { - userClient, err := DgraphClient(SockAddr) + ensureAddressesInitialized() + userClient, err := DgraphClient(GetSockAddr()) require.NoError(t, err) require.NoError(t, x.RetryUntilSuccess(10, 100*time.Millisecond, func() error { diff --git a/testutil/testaudit/audit.go b/testutil/testaudit/audit.go index 867b021ed1c..48d03c3d994 100644 --- a/testutil/testaudit/audit.go +++ b/testutil/testaudit/audit.go @@ -53,11 +53,11 @@ func TestGenerateAuditForTestDecrypt(t *testing.T) { t.Skip() zeroCmd := map[string][]string{ "/removeNode": {`--location`, "--request", "GET", "--ipv4", - fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/removeNode?id=3&group=1", testutil.GetSockAddrZeroHttp())}, "/assign": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/assign?what=uids&num=100", testutil.SockAddrZeroHttp)}, + fmt.Sprintf("%s/assign?what=uids&num=100", testutil.GetSockAddrZeroHttp())}, "/moveTablet": {"--location", "--request", "GET", "--ipv4", - fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.SockAddrZeroHttp)}} + fmt.Sprintf("%s/moveTablet?tablet=name&group=2", testutil.GetSockAddrZeroHttp())}} for _, c := range zeroCmd { cmd := exec.Command("curl", c...) diff --git a/testutil/zero.go b/testutil/zero.go index 394d41387a4..68482aff2af 100644 --- a/testutil/zero.go +++ b/testutil/zero.go @@ -52,7 +52,8 @@ type StateResponse struct { // GetState queries the /state endpoint in zero and returns the response. func GetState() (*StateResponse, error) { - resp, err := http.Get("http://" + SockAddrZeroHttp + "/state") + ensureAddressesInitialized() + resp, err := http.Get("http://" + GetSockAddrZeroHttp() + "/state") if err != nil { return nil, err } @@ -85,7 +86,8 @@ func GetStateHttps(tlsConfig *tls.Config) (*StateResponse, error) { TLSClientConfig: tlsConfig, }, } - resp, err := client.Get("https://" + SockAddrZeroHttp + "/state") + ensureAddressesInitialized() + resp, err := client.Get("https://" + GetSockAddrZeroHttp() + "/state") if err != nil { return nil, err } diff --git a/tlstest/acl/acl_over_tls_test.go b/tlstest/acl/acl_over_tls_test.go index 1d7a29d650a..76750afa0ce 100644 --- a/tlstest/acl/acl_over_tls_test.go +++ b/tlstest/acl/acl_over_tls_test.go @@ -28,7 +28,7 @@ func TestLoginOverTLS(t *testing.T) { // server-name "alpha1")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddr, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddr(), conf) require.NoError(t, err) for i := 0; i < 30; i++ { err = dg.LoginIntoNamespace(context.Background(), "groot", "password", x.RootNamespace) diff --git a/tlstest/certrequest/certrequest_test.go b/tlstest/certrequest/certrequest_test.go index b48c076fcd5..99e830050ce 100644 --- a/tlstest/certrequest/certrequest_test.go +++ b/tlstest/certrequest/certrequest_test.go @@ -22,7 +22,7 @@ import ( ) func TestAccessOverPlaintext(t *testing.T) { - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } @@ -37,7 +37,7 @@ func TestAccessWithCaCert(t *testing.T) { // server-name "node")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddr, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddr(), conf) require.NoError(t, err, "Unable to get dgraph client: %v", err) for i := 0; i < 20; i++ { err := dg.Alter(context.Background(), &api.Operation{DropAll: true}) @@ -56,7 +56,7 @@ func TestCurlAccessWithCaCert(t *testing.T) { // curl over plaintext should fail curlPlainTextArgs := []string{ "--ipv4", - "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlPlainTextArgs, &testutil.CurlFailureConfig{ @@ -66,7 +66,7 @@ func TestCurlAccessWithCaCert(t *testing.T) { curlArgs := []string{ "--cacert", "../tls/ca.crt", "--ipv4", - "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlArgs, &testutil.CurlFailureConfig{ diff --git a/tlstest/certrequireandverify/certrequireandverify_test.go b/tlstest/certrequireandverify/certrequireandverify_test.go index 66f810f2535..4c9bf4b6fc6 100644 --- a/tlstest/certrequireandverify/certrequireandverify_test.go +++ b/tlstest/certrequireandverify/certrequireandverify_test.go @@ -16,6 +16,7 @@ import ( "io" "net/http" "os" + "runtime" "testing" "time" @@ -34,7 +35,7 @@ func TestAccessWithoutClientCert(t *testing.T) { // server-name "node")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddrLocalhost, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddrLocalhost(), conf) require.NoError(t, err, "Unable to get dgraph client: %v", err) require.Error(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) } @@ -51,14 +52,17 @@ func TestAccessWithClientCert(t *testing.T) { // client-key "../tls/client.acl.key")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddr, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddr(), conf) require.NoError(t, err, "Unable to get dgraph client: %v", err) require.NoError(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) } func TestCurlAccessWithoutClientCert(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("Skipping curl test on non-linux OS") + } curlArgs := []string{ - "--cacert", "../tls/ca.crt", "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "--cacert", "../tls/ca.crt", "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlArgs, &testutil.CurlFailureConfig{ @@ -72,7 +76,7 @@ func TestCurlAccessWithClientCert(t *testing.T) { "--cacert", "../tls/ca.crt", "--cert", "../tls/client.acl.crt", "--key", "../tls/client.acl.key", - "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlArgs, &testutil.CurlFailureConfig{ @@ -103,7 +107,7 @@ func TestGQLAdminHealthWithClientCert(t *testing.T) { } healthCheckQuery := []byte(`{"query":"query {\n health {\n status\n }\n}"}`) - gqlAdminEndpoint := "https://" + testutil.SockAddrHttpLocalhost + "/admin" + gqlAdminEndpoint := "https://" + testutil.GetSockAddrHttpLocalhost() + "/admin" req, err := http.NewRequest("POST", gqlAdminEndpoint, bytes.NewBuffer(healthCheckQuery)) require.NoError(t, err, "Failed to create request : %v", err) req.Header.Set("Content-Type", "application/json") @@ -136,7 +140,7 @@ func TestGQLAdminHealthWithoutClientCert(t *testing.T) { } healthCheckQuery := []byte(`{"query":"query {\n health {\n message\n status\n }\n}"}`) - gqlAdminEndpoint := "https://" + testutil.SockAddrHttpLocalhost + "/admin" + gqlAdminEndpoint := "https://" + testutil.GetSockAddrHttpLocalhost() + "/admin" req, err := http.NewRequest("POST", gqlAdminEndpoint, bytes.NewBuffer(healthCheckQuery)) require.NoError(t, err, "Failed to create request : %v", err) req.Header.Set("Content-Type", "application/json") diff --git a/tlstest/certverifyifgiven/certverifyifgiven_test.go b/tlstest/certverifyifgiven/certverifyifgiven_test.go index 36050843352..a5b7f444621 100644 --- a/tlstest/certverifyifgiven/certverifyifgiven_test.go +++ b/tlstest/certverifyifgiven/certverifyifgiven_test.go @@ -27,7 +27,7 @@ func TestAccessWithoutClientCert(t *testing.T) { // server-name "node")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddrLocalhost, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddrLocalhost(), conf) require.NoError(t, err, "Unable to get dgraph client: %v", err) require.NoError(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) } @@ -44,14 +44,14 @@ func TestAccessWithClientCert(t *testing.T) { // client-key "../tls/client.acl.key")) - dg, err := testutil.DgraphClientWithCerts(testutil.SockAddrLocalhost, conf) + dg, err := testutil.DgraphClientWithCerts(testutil.GetSockAddrLocalhost(), conf) require.NoError(t, err, "Unable to get dgraph client: %v", err) require.NoError(t, dg.Alter(context.Background(), &api.Operation{DropAll: true})) } func TestCurlAccessWithoutClientCert(t *testing.T) { curlArgs := []string{ - "--cacert", "../tls/ca.crt", "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "--cacert", "../tls/ca.crt", "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlArgs, &testutil.CurlFailureConfig{ @@ -64,7 +64,7 @@ func TestCurlAccessWithClientCert(t *testing.T) { "--cacert", "../tls/ca.crt", "--cert", "../tls/client.acl.crt", "--key", "../tls/client.acl.key", - "https://" + testutil.SockAddrHttpLocalhost + "/alter", + "https://" + testutil.GetSockAddrHttpLocalhost() + "/alter", "-d", "name: string @index(exact) .", } testutil.VerifyCurlCmd(t, curlArgs, &testutil.CurlFailureConfig{ diff --git a/tlstest/mtls_internal/multi_group/multi_group_test.go b/tlstest/mtls_internal/multi_group/multi_group_test.go index 3f9ced05bd4..404c8d06360 100644 --- a/tlstest/mtls_internal/multi_group/multi_group_test.go +++ b/tlstest/mtls_internal/multi_group/multi_group_test.go @@ -92,7 +92,7 @@ func TestClusterSetupWithMultiGroup(t *testing.T) { } tlsConf, err := x.GenerateClientTLSConfig(c) require.NoError(t, err) - dgConn, err := grpc.NewClient(testutil.SockAddr, grpc.WithTransportCredentials(credentials.NewTLS(tlsConf))) + dgConn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(tlsConf))) require.NoError(t, err) client := dgo.NewDgraphClient(api.NewDgraphClient(dgConn)) runTests(t, client) diff --git a/tlstest/mtls_internal/single_node/single_node_test.go b/tlstest/mtls_internal/single_node/single_node_test.go index 1c960fe32c6..b43d3ccfb9c 100644 --- a/tlstest/mtls_internal/single_node/single_node_test.go +++ b/tlstest/mtls_internal/single_node/single_node_test.go @@ -92,7 +92,7 @@ func TestClusterSetup(t *testing.T) { } tlsConf, err := x.GenerateClientTLSConfig(c) require.NoError(t, err) - dgConn, err := grpc.NewClient(testutil.SockAddr, grpc.WithTransportCredentials(credentials.NewTLS(tlsConf))) + dgConn, err := grpc.NewClient(testutil.GetSockAddr(), grpc.WithTransportCredentials(credentials.NewTLS(tlsConf))) require.NoError(t, err) client := dgo.NewDgraphClient(api.NewDgraphClient(dgConn)) runTests(t, client) diff --git a/tlstest/zero_https/all_routes_tls/all_routes_tls_test.go b/tlstest/zero_https/all_routes_tls/all_routes_tls_test.go index 575f692031f..884103f23e9 100644 --- a/tlstest/zero_https/all_routes_tls/all_routes_tls_test.go +++ b/tlstest/zero_https/all_routes_tls/all_routes_tls_test.go @@ -53,7 +53,7 @@ func TestZeroWithAllRoutesTLSWithHTTPClient(t *testing.T) { } defer client.CloseIdleConnections() for _, test := range testCasesHttp { - request, err := http.NewRequest("GET", "http://"+testutil.SockAddrZeroHttp+test.url, nil) + request, err := http.NewRequest("GET", "http://"+testutil.GetSockAddrZeroHttp()+test.url, nil) require.NoError(t, err) do, err := client.Do(request) require.NoError(t, err) @@ -97,7 +97,7 @@ func TestZeroWithAllRoutesTLSWithTLSClient(t *testing.T) { defer client.CloseIdleConnections() for _, test := range testCasesHttps { - request, err := http.NewRequest("GET", "https://"+testutil.SockAddrZeroHttp+test.url, nil) + request, err := http.NewRequest("GET", "https://"+testutil.GetSockAddrZeroHttp()+test.url, nil) require.NoError(t, err) do, err := client.Do(request) require.NoError(t, err) diff --git a/tlstest/zero_https/no_tls/no_tls_test.go b/tlstest/zero_https/no_tls/no_tls_test.go index 1cb70f7d698..876843450a6 100644 --- a/tlstest/zero_https/no_tls/no_tls_test.go +++ b/tlstest/zero_https/no_tls/no_tls_test.go @@ -44,7 +44,7 @@ func TestZeroWithNoTLS(t *testing.T) { } defer client.CloseIdleConnections() for _, test := range testCasesHttp { - request, err := http.NewRequest("GET", "http://"+testutil.SockAddrZeroHttp+test.url, nil) + request, err := http.NewRequest("GET", "http://"+testutil.GetSockAddrZeroHttp()+test.url, nil) require.NoError(t, err) do, err := client.Do(request) require.NoError(t, err) diff --git a/worker/export_test.go b/worker/export_test.go index e347f62e8e0..bba3ad4225d 100644 --- a/worker/export_test.go +++ b/worker/export_test.go @@ -390,7 +390,7 @@ const exportRequest = `mutation export($format: String!) { }` func TestExportFormat(t *testing.T) { - adminUrl := "http://" + testutil.SockAddrHttp + "/admin" + adminUrl := "http://" + testutil.GetSockAddrHttp() + "/admin" require.NoError(t, testutil.CheckForGraphQLEndpointToReady(t)) params := testutil.GraphQLParams{ @@ -407,7 +407,7 @@ func TestExportFormat(t *testing.T) { require.NoError(t, json.NewDecoder(resp.Body).Decode(&data)) require.Equal(t, "Success", testutil.JsonGet(data, "data", "export", "response", "code").(string)) taskId := testutil.JsonGet(data, "data", "export", "taskId").(string) - testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp) + testutil.WaitForTask(t, taskId, false, testutil.GetSockAddrHttp()) params.Variables["format"] = "rdf" b, err = json.Marshal(params) diff --git a/worker/snapshot_test.go b/worker/snapshot_test.go index 6b48ee54097..941f84c2ac0 100644 --- a/worker/snapshot_test.go +++ b/worker/snapshot_test.go @@ -28,7 +28,7 @@ import ( func TestSnapshot(t *testing.T) { snapshotTs := uint64(0) - dg1, err := testutil.DgraphClient(testutil.SockAddr) + dg1, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } @@ -92,7 +92,7 @@ func TestSnapshot(t *testing.T) { const testSchema = "type Person { name: String }" // uploading new schema while alpha2 is not running so we can // test whether the stopped alpha gets new schema in snapshot - testutil.UpdateGQLSchema(t, testutil.SockAddrHttp, testSchema) + testutil.UpdateGQLSchema(t, testutil.GetSockAddrHttp(), testSchema) _ = waitForSnapshot(t, snapshotTs) t.Logf("Starting alpha2.\n") @@ -161,7 +161,7 @@ func verifySnapshot(t *testing.T, dg *dgo.Dgraph, num int) { func waitForSnapshot(t *testing.T, prevSnapTs uint64) uint64 { snapPattern := `"snapshotTs":"([0-9]*)"` for { - res, err := http.Get("http://" + testutil.SockAddrZeroHttp + "/state") + res, err := http.Get("http://" + testutil.GetSockAddrZeroHttp() + "/state") require.NoError(t, err) body, err := io.ReadAll(res.Body) res.Body.Close() diff --git a/worker/worker_test.go b/worker/worker_test.go index 1f1519e51dd..4181b645347 100644 --- a/worker/worker_test.go +++ b/worker/worker_test.go @@ -148,7 +148,7 @@ func initTest(t *testing.T, schemaStr string) { } func initClusterTest(t *testing.T, schemaStr string) *dgo.Dgraph { - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } @@ -239,7 +239,7 @@ func runQuery(dg *dgo.Dgraph, attr string, uids []uint64, srcFunc []string) (*ap } func BenchmarkEqFilter(b *testing.B) { - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { panic(err) } @@ -343,7 +343,7 @@ func TestProcessTaskIndexMLayer(t *testing.T) { func TestCountReverseIndex(t *testing.T) { schemaStr := "friend: [uid] @count ." - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } @@ -385,7 +385,7 @@ func TestCountReverseIndex(t *testing.T) { func TestCountIndexOverwrite(t *testing.T) { schemaStr := "friend: [uid] @reverse @count ." - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } @@ -407,7 +407,7 @@ func TestCountIndexOverwrite(t *testing.T) { func TestCountReverseWithDeletes(t *testing.T) { schemaStr := "friend: [uid] @reverse @count ." - dg, err := testutil.DgraphClient(testutil.SockAddr) + dg, err := testutil.DgraphClient(testutil.GetSockAddr()) if err != nil { t.Fatalf("Error while getting a dgraph client: %v", err) } diff --git a/xidmap/xidmap_test.go b/xidmap/xidmap_test.go index cb65c766ab7..dd458fac6aa 100644 --- a/xidmap/xidmap_test.go +++ b/xidmap/xidmap_test.go @@ -46,7 +46,7 @@ func getTestXidmapOpts(conn *grpc.ClientConn, db *badger.DB) XidMapOptions { } func TestXidmap(t *testing.T) { - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) require.NoError(t, err) require.NotNil(t, conn) @@ -108,7 +108,7 @@ func TestXidmapMemory(t *testing.T) { } }() - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) require.NoError(t, err) require.NotNil(t, conn) @@ -154,7 +154,7 @@ func TestXidmapMemory(t *testing.T) { // BenchmarkXidmapReadsRandom-16 428ns ± 2% func BenchmarkXidmapWrites(b *testing.B) { - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) if err != nil { b.Fatalf("Error setting up connection: %s", err.Error()) } @@ -173,7 +173,7 @@ func BenchmarkXidmapWrites(b *testing.B) { } func BenchmarkXidmapWritesRandom(b *testing.B) { - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) if err != nil { b.Fatalf("Error setting up connection: %s", err.Error()) } @@ -194,7 +194,7 @@ func BenchmarkXidmapWritesRandom(b *testing.B) { } func BenchmarkXidmapReads(b *testing.B) { - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) if err != nil { b.Fatalf("Error setting up connection: %s", err.Error()) } @@ -216,7 +216,7 @@ func BenchmarkXidmapReads(b *testing.B) { } func BenchmarkXidmapReadsRandom(b *testing.B) { - conn, err := x.SetupConnection(testutil.SockAddrZero, nil, false) + conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) if err != nil { b.Fatalf("Error setting up connection: %s", err.Error()) }