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."""

tests/test_txn.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def setUp(self):
3030

3131
helper.drop_all(self.client)
3232
helper.set_schema(self.client, 'name: string @index(fulltext) @upsert .')
33-
pydgraph.util.wait_for_indexing(self.client, "name", ["fulltext"], False, False)
3433

3534
def test_query_after_commit(self):
3635
txn = self.client.txn()
@@ -212,7 +211,6 @@ def test_read_from_new_client(self):
212211
txn.commit()
213212

214213
client2 = helper.create_client(self.TEST_SERVER_ADDR)
215-
client2.login("groot", "password")
216214
query = """{{
217215
me(func: uid("{uid:s}")) {{
218216
name
@@ -260,7 +258,6 @@ def test_best_effort_txn(self):
260258

261259
helper.drop_all(self.client)
262260
helper.set_schema(self.client, 'name: string @index(exact) .')
263-
pydgraph.util.wait_for_indexing(self.client, "name", ["exact"], False, False)
264261

265262
txn = self.client.txn()
266263
_ = txn.mutate(set_obj={'name': 'Manish'})
@@ -387,7 +384,6 @@ def test_read_index_key_same_txn(self):
387384

388385
helper.drop_all(self.client)
389386
helper.set_schema(self.client, 'name: string @index(exact) .')
390-
pydgraph.util.wait_for_indexing(self.client, "name", ["exact"], False, False)
391387

392388
txn = self.client.txn()
393389
response = txn.mutate(set_obj={'name': 'Manish'})
@@ -411,7 +407,6 @@ def test_non_string_variable(self):
411407
in an Exception."""
412408
helper.drop_all(self.client)
413409
helper.set_schema(self.client, 'name: string @index(exact) .')
414-
pydgraph.util.wait_for_indexing(self.client, "name", ["exact"], False, False)
415410

416411
txn = self.client.txn()
417412
query = """

tests/test_type_system.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import logging
2121
import unittest
2222

23-
from . import helper
24-
import pydgraph
23+
from tests import helper
24+
2525

2626
class TestTypeSystem(helper.ClientIntegrationTestCase):
2727
def setUp(self):
@@ -38,7 +38,6 @@ def setUp(self):
3838
"""
3939

4040
helper.set_schema(self.client, schema)
41-
pydgraph.util.wait_for_indexing(self.client, "name", ["term", "exact"], False, False)
4241

4342
def test_type_deletion_failure(self):
4443
"""It tries to delete all predicates of a node without having any type"""

tests/test_upsert_block.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import json
2222

2323
from . import helper
24-
import pydgraph
24+
2525

2626
class TestUpsertBlock(helper.ClientIntegrationTestCase):
2727
"""Tests for Upsert Block"""
@@ -30,7 +30,6 @@ def setUp(self):
3030
super(TestUpsertBlock, self).setUp()
3131
helper.drop_all(self.client)
3232
helper.set_schema(self.client, 'name: string @index(term) @upsert .')
33-
pydgraph.util.wait_for_indexing(self.client, "name", ["term"], False, False)
3433

3534
def test_upsert_block_one_mutation(self):
3635
txn = self.client.txn()

0 commit comments

Comments
 (0)