Skip to content

Commit a5c469d

Browse files
chore: Modify test to remove flakiness caused by explicit uids (#6080)
1 parent e45c296 commit a5c469d

File tree

1 file changed

+21
-75
lines changed

1 file changed

+21
-75
lines changed

systest/loader/loader_test.go

Lines changed: 21 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@
1717
package main
1818

1919
import (
20-
"bytes"
21-
"encoding/json"
22-
"fmt"
20+
"context"
2321
"io/ioutil"
24-
"net/http"
2522
"os"
2623
"os/exec"
2724
"path/filepath"
28-
"strings"
2925
"testing"
3026

3127
"github.com/stretchr/testify/require"
3228

29+
"github.com/dgraph-io/dgo/v200/protos/api"
3330
"github.com/dgraph-io/dgraph/testutil"
31+
"github.com/dgraph-io/dgraph/x"
3432
)
3533

34+
// TestLoaderXidmap checks that live loader re-uses xidmap on loading data from two different files
3635
func TestLoaderXidmap(t *testing.T) {
36+
dg, err := testutil.DgraphClient(testutil.SockAddr)
37+
require.NoError(t, err)
38+
ctx := context.Background()
39+
testutil.DropAll(t, dg)
3740
tmpDir, err := ioutil.TempDir("", "loader_test")
3841
require.NoError(t, err)
3942
defer os.RemoveAll(tmpDir)
@@ -63,80 +66,23 @@ func TestLoaderXidmap(t *testing.T) {
6366
liveCmd.Stderr = os.Stdout
6467
require.NoError(t, liveCmd.Run())
6568

66-
exportRequest := `mutation {
67-
export(input: {format: "rdf"}) {
68-
response {
69-
code
70-
message
69+
op := api.Operation{Schema: "name: string @index(exact) ."}
70+
x.Check(dg.Alter(ctx, &op))
71+
72+
query := `
73+
{
74+
q(func: eq(name, "Alice")) {
75+
age
76+
location
77+
friend{
78+
name
7179
}
7280
}
7381
}`
82+
expected := `{"q":[{"age":"13","location":"Wonderland","friend":[{"name":"Bob"}]}]}`
7483

75-
adminUrl := "http://" + testutil.SockAddrHttp + "/admin"
76-
params := testutil.GraphQLParams{
77-
Query: exportRequest,
78-
Variables: map[string]interface{}{"format": "json"},
79-
}
80-
b, err := json.Marshal(params)
81-
require.NoError(t, err)
82-
resp, err := http.Post(adminUrl, "application/json", bytes.NewBuffer(b))
83-
require.NoError(t, err)
84-
defer resp.Body.Close()
85-
b, err = ioutil.ReadAll(resp.Body)
86-
require.NoError(t, err)
87-
expected := `{
88-
"export": {
89-
"response": {
90-
"code": "Success",
91-
"message": "Export completed."
92-
}
93-
}
94-
}`
95-
res1 := &testutil.GraphQLResponse{}
96-
err = json.Unmarshal(b, res1)
97-
require.NoError(t, err)
98-
require.JSONEq(t, expected, string(res1.Data))
99-
100-
require.NoError(t, copyExportFiles(tmpDir))
101-
102-
dataFile, err := findFile(filepath.Join(tmpDir, "export"), ".rdf.gz")
84+
resp, err := dg.NewReadOnlyTxn().Query(ctx, query)
10385
require.NoError(t, err)
86+
testutil.CompareJSON(t, expected, string(resp.GetJson()))
10487

105-
cmd := fmt.Sprintf("gunzip -c %s | sort", dataFile)
106-
out, err := exec.Command("sh", "-c", cmd).Output()
107-
require.NoError(t, err)
108-
109-
expected = `<0x1> <age> "13" .
110-
<0x1> <friend> <0x2711> .
111-
<0x1> <location> "Wonderland" .
112-
<0x1> <name> "Alice" .
113-
<0x2711> <name> "Bob" .
114-
`
115-
require.Equal(t, expected, string(out))
116-
}
117-
118-
func copyExportFiles(tmpDir string) error {
119-
exportPath := filepath.Join(tmpDir, "export")
120-
if err := os.MkdirAll(exportPath, 0755); err != nil {
121-
return err
122-
}
123-
124-
srcPath := "alpha1:/data/alpha1/export"
125-
dstPath := filepath.Join(tmpDir, "export")
126-
return testutil.DockerCp(srcPath, dstPath)
127-
}
128-
129-
func findFile(dir string, ext string) (string, error) {
130-
var fp string
131-
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
132-
if err != nil {
133-
return err
134-
}
135-
if strings.HasSuffix(path, ext) {
136-
fp = path
137-
return nil
138-
}
139-
return nil
140-
})
141-
return fp, err
14288
}

0 commit comments

Comments
 (0)