Skip to content

Commit 3864368

Browse files
committed
Merge branch 'master' of github.com:dgraph-io/dgraph into jatin/GRAPHQL-924
2 parents 5296787 + 2f10119 commit 3864368

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2283
-247
lines changed

dgraph/cmd/alpha/http_test.go

+18-100
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func runGzipWithRetry(contentType, url string, buf io.Reader, gzReq, gzResp bool
6767
return nil, err
6868
}
6969
req.Header.Add("Content-Type", contentType)
70-
req.Header.Set("X-Dgraph-AccessToken", token.AccessJwt)
70+
req.Header.Set("X-Dgraph-AccessToken", token.getAccessJWTToken())
7171

7272
if gzReq {
7373
req.Header.Set("Content-Encoding", "gzip")
@@ -79,15 +79,10 @@ func runGzipWithRetry(contentType, url string, buf io.Reader, gzReq, gzResp bool
7979

8080
resp, err = client.Do(req)
8181
if err != nil && strings.Contains(err.Error(), "Token is expired") {
82-
newToken, err := testutil.HttpLogin(&testutil.LoginParams{
83-
Endpoint: addr + "/admin",
84-
RefreshJwt: token.RefreshToken,
85-
})
82+
err := token.refreshToken()
8683
if err != nil {
8784
return nil, err
8885
}
89-
token.AccessJwt = newToken.AccessJwt
90-
token.RefreshToken = newToken.RefreshToken
9186
continue
9287
} else if err != nil {
9388
return nil, err
@@ -168,33 +163,8 @@ func queryWithGz(queryText, contentType, debug, timeout string, gzReq, gzResp bo
168163
}
169164

170165
func queryWithTs(queryText, contentType, debug string, ts uint64) (string, uint64, error) {
171-
params := make([]string, 0, 2)
172-
if debug != "" {
173-
params = append(params, "debug="+debug)
174-
}
175-
if ts != 0 {
176-
params = append(params, fmt.Sprintf("startTs=%v", strconv.FormatUint(ts, 10)))
177-
}
178-
url := addr + "/query?" + strings.Join(params, "&")
179-
180-
_, body, err := runWithRetries("POST", contentType, url, queryText)
181-
if err != nil {
182-
return "", 0, err
183-
}
184-
185-
var r res
186-
if err := json.Unmarshal(body, &r); err != nil {
187-
return "", 0, err
188-
}
189-
startTs := r.Extensions.Txn.StartTs
190-
191-
// Remove the extensions.
192-
r2 := res{
193-
Data: r.Data,
194-
}
195-
output, err := json.Marshal(r2)
196-
197-
return string(output), startTs, err
166+
out, startTs, _, err := queryWithTsForResp(queryText, contentType, debug, ts)
167+
return out, startTs, err
198168
}
199169

200170
// queryWithTsForResp query the dgraph and returns it's http response and result.
@@ -296,57 +266,34 @@ func createRequest(method, contentType, url string, body string) (*http.Request,
296266

297267
func runWithRetries(method, contentType, url string, body string) (
298268
*x.QueryResWithData, []byte, error) {
299-
300-
req, err := createRequest(method, contentType, url, body)
301-
if err != nil {
302-
return nil, nil, err
303-
}
304-
305-
qr, respBody, err := runRequest(req)
306-
if err != nil && strings.Contains(err.Error(), "Token is expired") {
307-
token, err = testutil.HttpLogin(&testutil.LoginParams{
308-
Endpoint: addr + "/admin",
309-
RefreshJwt: token.RefreshToken,
310-
})
311-
if err != nil {
312-
return nil, nil, err
313-
}
314-
315-
// create a new request since the previous request would have been closed upon the err
316-
retryReq, err := createRequest(method, contentType, url, body)
317-
if err != nil {
318-
return nil, nil, err
319-
}
320-
321-
return runRequest(retryReq)
322-
}
269+
qr, respBody, _, err := runWithRetriesForResp(method, contentType, url, body)
323270
return qr, respBody, err
324271
}
325272

326273
// attach the grootAccessJWT to the request and sends the http request
327-
func runRequest(req *http.Request) (*x.QueryResWithData, []byte, error) {
274+
func runRequest(req *http.Request) (*x.QueryResWithData, []byte, *http.Response, error) {
328275
client := &http.Client{}
329-
req.Header.Set("X-Dgraph-AccessToken", token.AccessJwt)
276+
req.Header.Set("X-Dgraph-AccessToken", token.getAccessJWTToken())
330277
resp, err := client.Do(req)
331278
if err != nil {
332-
return nil, nil, err
279+
return nil, nil, resp, err
333280
}
334281
if status := resp.StatusCode; status != http.StatusOK {
335-
return nil, nil, errors.Errorf("Unexpected status code: %v", status)
282+
return nil, nil, resp, errors.Errorf("Unexpected status code: %v", status)
336283
}
337284

338285
defer resp.Body.Close()
339286
body, err := ioutil.ReadAll(resp.Body)
340287
if err != nil {
341-
return nil, nil, errors.Errorf("unable to read from body: %v", err)
288+
return nil, nil, resp, errors.Errorf("unable to read from body: %v", err)
342289
}
343290

344291
qr := new(x.QueryResWithData)
345292
json.Unmarshal(body, qr) // Don't check error.
346293
if len(qr.Errors) > 0 {
347-
return nil, nil, errors.New(qr.Errors[0].Message)
294+
return nil, nil, resp, errors.New(qr.Errors[0].Message)
348295
}
349-
return qr, body, nil
296+
return qr, body, resp, nil
350297
}
351298

352299
func runWithRetriesForResp(method, contentType, url string, body string) (
@@ -357,12 +304,9 @@ func runWithRetriesForResp(method, contentType, url string, body string) (
357304
return nil, nil, nil, err
358305
}
359306

360-
qr, respBody, resp, err := runRequestForResp(req)
307+
qr, respBody, resp, err := runRequest(req)
361308
if err != nil && strings.Contains(err.Error(), "Token is expired") {
362-
token, err = testutil.HttpLogin(&testutil.LoginParams{
363-
Endpoint: addr + "/admin",
364-
RefreshJwt: token.RefreshToken,
365-
})
309+
err = token.refreshToken()
366310
if err != nil {
367311
return nil, nil, nil, err
368312
}
@@ -373,37 +317,11 @@ func runWithRetriesForResp(method, contentType, url string, body string) (
373317
return nil, nil, resp, err
374318
}
375319

376-
return runRequestForResp(retryReq)
320+
return runRequest(retryReq)
377321
}
378322
return qr, respBody, resp, err
379323
}
380324

381-
// attach the grootAccessJWT to the request and sends the http request
382-
func runRequestForResp(req *http.Request) (*x.QueryResWithData, []byte, *http.Response, error) {
383-
client := &http.Client{}
384-
req.Header.Set("X-Dgraph-AccessToken", token.AccessJwt)
385-
resp, err := client.Do(req)
386-
if err != nil {
387-
return nil, nil, resp, err
388-
}
389-
if status := resp.StatusCode; status != http.StatusOK {
390-
return nil, nil, resp, errors.Errorf("Unexpected status code: %v", status)
391-
}
392-
393-
defer resp.Body.Close()
394-
body, err := ioutil.ReadAll(resp.Body)
395-
if err != nil {
396-
return nil, nil, resp, errors.Errorf("unable to read from body: %v", err)
397-
}
398-
399-
qr := new(x.QueryResWithData)
400-
json.Unmarshal(body, qr) // Don't check error.
401-
if len(qr.Errors) > 0 {
402-
return nil, nil, resp, errors.New(qr.Errors[0].Message)
403-
}
404-
return qr, body, resp, nil
405-
}
406-
407325
func commitWithTs(keys, preds []string, ts uint64) error {
408326
url := addr + "/commit"
409327
if ts != 0 {
@@ -421,7 +339,7 @@ func commitWithTs(keys, preds []string, ts uint64) error {
421339
if err != nil {
422340
return err
423341
}
424-
_, _, err = runRequest(req)
342+
_, _, _, err = runRequest(req)
425343
return err
426344
}
427345

@@ -439,7 +357,7 @@ func commitWithTsKeysOnly(keys []string, ts uint64) error {
439357
if err != nil {
440358
return err
441359
}
442-
_, _, err = runRequest(req)
360+
_, _, _, err = runRequest(req)
443361
return err
444362
}
445363

@@ -633,7 +551,7 @@ func TestTransactionBasicOldCommitFormat(t *testing.T) {
633551
url := fmt.Sprintf("%s/commit?startTs=%d&abort=true", addr, ts)
634552
req, err := http.NewRequest("POST", url, nil)
635553
require.NoError(t, err)
636-
_, _, err = runRequest(req)
554+
_, _, _, err = runRequest(req)
637555
require.NoError(t, err)
638556
}
639557

dgraph/cmd/alpha/metrics_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func fetchMetric(t *testing.T) int {
7878
requiredMetric := "dgraph_txn_aborts_total"
7979
req, err := http.NewRequest("GET", addr+"/debug/prometheus_metrics", nil)
8080
require.NoError(t, err)
81-
_, body, err := runRequest(req)
81+
_, body, _, err := runRequest(req)
8282
require.NoError(t, err)
8383
metricsMap, err := extractMetrics(string(body))
8484
require.NoError(t, err)
@@ -93,7 +93,7 @@ func TestMetrics(t *testing.T) {
9393
req, err := http.NewRequest("GET", addr+"/debug/prometheus_metrics", nil)
9494
require.NoError(t, err)
9595

96-
_, body, err := runRequest(req)
96+
_, body, _, err := runRequest(req)
9797
require.NoError(t, err)
9898
metricsMap, err := extractMetrics(string(body))
9999
require.NoError(t, err, "Unable to get the metrics map: %v", err)

dgraph/cmd/alpha/run_test.go

+35-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"net"
2727
"os"
2828
"strings"
29+
"sync"
2930
"sync/atomic"
3031
"testing"
3132
"time"
@@ -1655,9 +1656,35 @@ func TestGeoValidWkbData(t *testing.T) {
16551656

16561657
var addr string
16571658

1658-
// the grootAccessJWT stores the access JWT extracted from the response
1659-
// of http login
1660-
var token *testutil.HttpToken
1659+
type Token struct {
1660+
token *testutil.HttpToken
1661+
sync.RWMutex
1662+
}
1663+
1664+
//// the grootAccessJWT stores the access JWT extracted from the response
1665+
//// of http login
1666+
var token *Token
1667+
1668+
func (t *Token) getAccessJWTToken() string {
1669+
t.RLock()
1670+
defer t.RUnlock()
1671+
return t.token.AccessJwt
1672+
}
1673+
1674+
func (t *Token) refreshToken() error {
1675+
t.Lock()
1676+
defer t.Unlock()
1677+
newToken, err := testutil.HttpLogin(&testutil.LoginParams{
1678+
Endpoint: addr + "/admin",
1679+
RefreshJwt: t.token.RefreshToken,
1680+
})
1681+
if err != nil {
1682+
return err
1683+
}
1684+
t.token.AccessJwt = newToken.AccessJwt
1685+
t.token.RefreshToken = newToken.RefreshToken
1686+
return nil
1687+
}
16611688

16621689
func TestMain(m *testing.M) {
16631690
addr = "http://" + testutil.SockAddrHttp
@@ -1670,8 +1697,11 @@ func TestMain(m *testing.M) {
16701697
if _, err := zc.AssignUids(context.Background(), &pb.Num{Val: 1e6}); err != nil {
16711698
log.Fatal(err)
16721699
}
1673-
token = testutil.GrootHttpLogin(addr + "/admin")
1674-
1700+
httpToken := testutil.GrootHttpLogin(addr + "/admin")
1701+
token = &Token{
1702+
token: httpToken,
1703+
RWMutex: sync.RWMutex{},
1704+
}
16751705
r := m.Run()
16761706
os.Exit(r)
16771707
}

edgraph/access_ee.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (s *Server) authenticateLogin(ctx context.Context, request *api.LoginReques
137137
}
138138

139139
if user == nil {
140-
return nil, errors.Errorf("unable to authenticate through refresh token: "+
140+
return nil, errors.Errorf("unable to authenticate: "+
141141
"invalid username or password")
142142
}
143143

@@ -154,8 +154,8 @@ func (s *Server) authenticateLogin(ctx context.Context, request *api.LoginReques
154154
}
155155

156156
if user == nil {
157-
return nil, errors.Errorf("unable to authenticate through password: "+
158-
"invalid username or passowrd")
157+
return nil, errors.Errorf("unable to authenticate: "+
158+
"invalid username or password")
159159
}
160160
if !user.PasswordMatch {
161161
return nil, x.ErrorInvalidLogin

netlify.toml

+8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
HUGO_VERSION = "0.74.3"
99
LOOP = "false"
1010

11+
[context.deploy-preview]
12+
command = "./scripts/local.sh --preview $DEPLOY_PRIME_URL"
13+
1114
[context.deploy-preview.environment]
15+
HUGO_VERSION = "0.74.3"
16+
LOOP = "false"
17+
HOST = "/"
18+
19+
[context.branch-deploy.environment]
1220
HUGO_VERSION = "0.74.3"
1321
LOOP = "false"
1422
HOST = "/"

systest/1million/1million_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9271,7 +9271,7 @@ func Test1Million(t *testing.T) {
92719271
}
92729272

92739273
for _, tt := range tc {
9274-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
9274+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
92759275
resp, err := dg.NewTxn().Query(ctx, tt.query)
92769276
cancel()
92779277

systest/21million/common/run_queries.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestQueriesFor21Million(t *testing.T) {
7474
for retry := 0; retry < 3; retry++ {
7575
// If a query takes too long to run, it probably means dgraph is stuck and there's
7676
// no point in waiting longer or trying more tests.
77-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
77+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
7878
resp, err := dg.NewTxn().Query(ctx, bodies[0])
7979
cancel()
8080

systest/mutations_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ func CountIndexConcurrentSetDelUIDList(t *testing.T, c *dgo.Dgraph) {
17151715
err := c.Alter(ctx, op)
17161716
require.NoError(t, err)
17171717

1718-
r := rand.New(rand.NewSource(time.Now().Unix()))
1718+
rand.Seed(time.Now().Unix())
17191719
maxUID := 100
17201720
txnTotal := uint64(1000)
17211721
txnCur := uint64(0)
@@ -1733,7 +1733,7 @@ func CountIndexConcurrentSetDelUIDList(t *testing.T, c *dgo.Dgraph) {
17331733
if atomic.AddUint64(&txnCur, 1) > txnTotal {
17341734
break
17351735
}
1736-
id := 2 + int(r.Int31n(int32(maxUID))) // 1 id subject id.
1736+
id := 2 + int(rand.Int31n(int32(maxUID))) // 1 id subject id.
17371737
mu := &api.Mutation{
17381738
CommitNow: true,
17391739
}
@@ -1784,7 +1784,7 @@ func CountIndexConcurrentSetDelUIDList(t *testing.T, c *dgo.Dgraph) {
17841784
if atomic.AddUint64(&txnCur, 1) > txnTotal {
17851785
break
17861786
}
1787-
id := insertedUids[r.Intn(len(insertedUids))]
1787+
id := insertedUids[rand.Intn(len(insertedUids))]
17881788
mu := &api.Mutation{
17891789
CommitNow: true,
17901790
}
@@ -1836,7 +1836,7 @@ func CountIndexConcurrentSetDelScalarPredicate(t *testing.T, c *dgo.Dgraph) {
18361836
err := c.Alter(ctx, op)
18371837
require.NoError(t, err)
18381838

1839-
r := rand.New(rand.NewSource(time.Now().Unix()))
1839+
rand.Seed(time.Now().Unix())
18401840
txnTotal := uint64(100)
18411841
txnCur := uint64(0)
18421842

@@ -1850,7 +1850,7 @@ func CountIndexConcurrentSetDelScalarPredicate(t *testing.T, c *dgo.Dgraph) {
18501850
if atomic.AddUint64(&txnCur, 1) > txnTotal {
18511851
break
18521852
}
1853-
id := int(r.Int31n(int32(10000)))
1853+
id := int(rand.Int31n(int32(10000)))
18541854
mu := &api.Mutation{
18551855
CommitNow: true,
18561856
}

0 commit comments

Comments
 (0)