Skip to content

Commit 07ed42a

Browse files
committed
Revert "Fix tests now that we do indexing in background (#120)"
This reverts commit 4da27dc.
1 parent 15cc46f commit 07ed42a

File tree

13 files changed

+11
-76
lines changed

13 files changed

+11
-76
lines changed

README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ op = pydgraph.Operation(schema=schema)
9090
client.alter(op)
9191
```
9292

93-
Starting Dgraph version `20.3.0`, indexes are computed in the background.
94-
This requires that you wait for indexing to complete before running queries.
95-
You could do that using following code.
96-
97-
```python
98-
pydgraph.util.wait_for_indexing(client, "name", ["exact"], False, False)
99-
```
100-
10193
`Operation` contains other fields as well, including drop predicate and drop all.
10294
Drop all is useful if you wish to discard all the data, and start from a clean
10395
slate, without bringing the instance down.

examples/simple/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ set up the Dgraph cluster:
1515
version: "3.2"
1616
services:
1717
zero:
18-
image: dgraph/dgraph:latest
18+
image: dgraph/dgraph:v1.1.0
1919
restart: on-failure
2020
command: dgraph zero --my=zero:5080
2121
server:
22-
image: dgraph/dgraph:latest
22+
image: dgraph/dgraph:v1.1.0
2323
ports:
2424
- 8080:8080
2525
- 9080:9080

examples/simple/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pydgraph>=2.0.2
1+
pydgraph>=1.0a1.0

examples/simple/simple.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def create_client(client_stub):
1616

1717
# Drop All - discard all data and start from a clean slate.
1818
def drop_all(client):
19-
client.alter(pydgraph.Operation(drop_all=True))
19+
return client.alter(pydgraph.Operation(drop_all=True))
2020

2121

2222
# Set schema.
@@ -38,9 +38,7 @@ def set_schema(client):
3838
dob
3939
}
4040
"""
41-
client.alter(pydgraph.Operation(schema=schema))
42-
pydgraph.util.wait_for_indexing(client, "name", ["exact"], False, False)
43-
pydgraph.util.wait_for_indexing(client, "friend", [], False, True)
41+
return client.alter(pydgraph.Operation(schema=schema))
4442

4543

4644
# Create data using JSON.

examples/tls/tls_example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def main():
3434
'''
3535
op = pydgraph.Operation(schema=schema)
3636
client.alter(op)
37-
pydgraph.util.wait_for_indexing(client, "name", ["exact"], False, False)
3837

3938
# Mutate
4039
dgraph = {

pydgraph/util.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414

1515
"""Various utility functions."""
1616

17-
import json
1817
import sys
19-
import time
2018

2119
from pydgraph.meta import VERSION
2220

@@ -36,32 +34,3 @@ def is_string(string):
3634

3735
def is_jwt_expired(exception):
3836
return 'Token is expired' in str(exception)
39-
40-
41-
def wait_for_indexing(client, pred, tokenizers, count, reverse):
42-
"""Waits for indexes to be built."""
43-
tokenizers.sort()
44-
query = "schema(pred: [{}]){{tokenizer reverse count}}".format(pred)
45-
while True:
46-
resp = client.txn(read_only=True).query(query)
47-
if has_indexes(resp, tokenizers, count, reverse):
48-
break
49-
time.sleep(0.1)
50-
51-
def has_indexes(resp, tokenizers, count, reverse):
52-
schema = json.loads(resp.json)
53-
if len(schema["schema"]) != 1:
54-
return False
55-
index = schema["schema"][0]
56-
if len(index.get("tokenizer", [])) != len(tokenizers):
57-
return False
58-
if index.get("count", False) != count or index.get("reverse", False) != reverse:
59-
return False
60-
# if no tokenizer is expected
61-
if len(index.get("tokenizer", [])) == 0:
62-
return True
63-
index["tokenizer"].sort()
64-
for i in range(len(tokenizers)):
65-
if tokenizers[i] != index["tokenizer"][i]:
66-
return False
67-
return True

tests/helper.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
__author__ = 'Garvit Pahal <[email protected]>'
1818
__maintainer__ = 'Martin Martinez Rivera <[email protected]>'
1919

20-
import time
2120
import unittest
2221

2322
import pydgraph
@@ -59,11 +58,4 @@ def setUp(self):
5958
"""Sets up the client."""
6059

6160
self.client = create_client(self.TEST_SERVER_ADDR)
62-
while True:
63-
try:
64-
self.client.login("groot", "password")
65-
break
66-
except Exception as e:
67-
if not "user not found" in str(e):
68-
raise e
69-
time.sleep(0.1)
61+
self.client.login("groot", "password")

tests/test_acct_upsert.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ def setUp(self):
5252
age: int @index(int) @upsert .
5353
when: int .
5454
""")
55-
pydgraph.util.wait_for_indexing(self.client, "first", ["term"], False, False)
56-
pydgraph.util.wait_for_indexing(self.client, "last", ["hash"], False, False)
5755

5856
def test_account_upsert(self):
5957
"""Run upserts concurrently."""
@@ -113,7 +111,6 @@ def assert_changes(self, firsts, accounts):
113111
def upsert_account(addr, account, success_ctr, retry_ctr):
114112
"""Runs upsert operation."""
115113
client = helper.create_client(addr)
116-
client.login("groot", "password")
117114
query = """{{
118115
acct(func:eq(first, "{first}")) @filter(eq(last, "{last}") AND eq(age, {age})) {{
119116
uid
@@ -170,7 +167,6 @@ def upsert_account(addr, account, success_ctr, retry_ctr):
170167
def upsert_account_upsert_block(addr, account, success_ctr, retry_ctr):
171168
"""Runs upsert operation."""
172169
client = helper.create_client(addr)
173-
client.login("groot", "password")
174170
query = """{{
175171
acct(func:eq(first, "{first}")) @filter(eq(last, "{last}") AND eq(age, {age})) {{
176172
u as uid

tests/test_acl.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import unittest
2424

2525
from . import helper
26-
import pydgraph
26+
2727

2828
class TestACL(helper.ClientIntegrationTestCase):
2929
user_id = 'alice'
@@ -68,8 +68,6 @@ def change_permission(self, permission):
6868
bash_command = "dgraph acl -a " + self.server_addr + " mod -g " + self.group_id + \
6969
" -p name -m " + str(permission) + " -x password"
7070
self.run_command(bash_command)
71-
# wait for ACL cache to be refreshed.
72-
time.sleep(6)
7371

7472
def insert_sample_data(self):
7573
txn = self.client.txn()
@@ -128,12 +126,11 @@ def try_writing(self, expected):
128126
def try_altering(self, expected):
129127
try:
130128
helper.set_schema(self.alice_client, 'name: string @index(exact, term) .')
131-
pydgraph.util.wait_for_indexing(self.alice_client, "name", ["exact", "term"], False, False)
132129
if not expected:
133130
self.fail("Acl test failed: Alter successful without permission")
134131
except Exception as e:
135132
if expected:
136-
self.fail("Acl test failed: Alter failed for alterable predicate.\n" + str(e))
133+
self.fail("Acl test failed: Alter failed for altreble predicate.\n" + str(e))
137134

138135

139136
def suite():

tests/test_queries.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def setUp(self):
3535

3636
helper.drop_all(self.client)
3737
helper.set_schema(self.client, 'name: string @index(term) .')
38-
pydgraph.util.wait_for_indexing(self.client, "name", ["term"], False, False)
3938

4039
def test_mutation_and_query(self):
4140
"""Runs mutation and verifies queries see the results."""

0 commit comments

Comments
 (0)