Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-01-07 18:13:01 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-01-07 18:13:01 (GMT)
commit7d991afe7a2f37202130a931c2780692db509274 (patch)
treea92d300a4361f90ce983b1d7ccdc6e1bfd705748
parent137ea1defcf14ece0386dbc4e9029fb5c3586ffa (diff)
Test server crash with actualizing indexes
-rw-r--r--tests/__init__.py14
-rwxr-xr-xtests/units/document.py143
2 files changed, 104 insertions, 53 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 5ebf1e4..8cebfa5 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -7,6 +7,7 @@ import signal
import shutil
import logging
import unittest
+import threading
from wsgiref.simple_server import make_server
from os.path import dirname, join, exists, abspath
@@ -20,6 +21,8 @@ import restful_document as rd
from active_document import env as _env
+gobject.threads_init()
+
root = abspath(dirname(__file__))
tmproot = join(root, '.tmp')
tmpdir = None
@@ -66,6 +69,9 @@ class Test(unittest.TestCase):
_env.LAYOUT_VERSION = 1
ad.data_root.value = tmpdir + '/db'
+ ad.index_flush_timeout.value = 0
+ ad.index_flush_threshold.value = 0
+ ad.index_pool.value = 0
def tearDown(self):
while Test.httpd_pids:
@@ -119,7 +125,13 @@ class Test(unittest.TestCase):
logging.basicConfig(level=logging.DEBUG, filename=tmpdir + '.http.log')
httpd = make_server('', port, rd.Router(classes))
- httpd.serve_forever()
+ mainloop = gobject.MainLoop()
+
+ httpd_thread = threading.Thread(target=httpd.serve_forever)
+ httpd_thread.daemon = True
+ httpd_thread.start()
+
+ mainloop.run()
def httpdown(self, port):
pid = Test.httpd_pids[port]
diff --git a/tests/units/document.py b/tests/units/document.py
index 12389d1..6c6be72 100755
--- a/tests/units/document.py
+++ b/tests/units/document.py
@@ -11,69 +11,39 @@ import active_document as ad
import restful_document as rd
-class Resource(restkit.Resource):
+class Vote(ad.AggregatorProperty):
- def get(self, path=None, headers=None, **kwargs):
- if headers is None:
- headers = {}
- if 'Content-Type' not in headers:
- headers['Content-Type'] = 'application/json'
- return restkit.Resource.get(self, path, headers=headers, **kwargs)
+ @property
+ def value(self):
+ return -1
- def put(self, path=None, headers=None, **kwargs):
- if headers is None:
- headers = {}
- if 'Content-Type' not in headers:
- headers['Content-Type'] = 'application/json'
- return restkit.Resource.put(self, path, headers=headers, **kwargs)
- def post(self, path=None, headers=None, **kwargs):
- if headers is None:
- headers = {}
- if 'Content-Type' not in headers:
- headers['Content-Type'] = 'application/json'
- return restkit.Resource.post(self, path, headers=headers, **kwargs)
-
- def delete(self, path=None, headers=None, **kwargs):
- if headers is None:
- headers = {}
- if 'Content-Type' not in headers:
- headers['Content-Type'] = 'application/json'
- return restkit.Resource.delete(self, path, headers=headers, **kwargs)
+class Document(rd.Document):
+ @ad.active_property(slot=1, prefix='A', full_text=True)
+ def term(self, value):
+ return value
-class DocumentTest(tests.Test):
-
- def test_Walkthrough(self):
+ @ad.active_property(ad.StoredProperty)
+ def stored(self, value):
+ return value
- class Vote(ad.AggregatorProperty):
+ @ad.active_property(ad.BlobProperty)
+ def blob(self, value):
+ return value
- @property
- def value(self):
- return -1
+ @ad.active_property(ad.CounterProperty, slot=2)
+ def counter(self, value):
+ return value
- class Document(rd.Document):
+ @ad.active_property(Vote, counter='counter')
+ def vote(self, value):
+ return value
- @ad.active_property(slot=1, prefix='A', full_text=True)
- def term(self, value):
- return value
- @ad.active_property(ad.StoredProperty)
- def stored(self, value):
- return value
-
- @ad.active_property(ad.BlobProperty)
- def blob(self, value):
- return value
-
- @ad.active_property(ad.CounterProperty, slot=2)
- def counter(self, value):
- return value
-
- @ad.active_property(Vote, counter='counter')
- def vote(self, value):
- return value
+class DocumentTest(tests.Test):
+ def test_Walkthrough(self):
self.httpd(8000, [Document])
rest = Resource('http://localhost:8000')
@@ -176,6 +146,75 @@ class DocumentTest(tests.Test):
'documents': sorted([])},
json.loads(rest.get('/document', reply='guid,stored,term,vote,counter').body_string()))
+ def test_ServerCrash(self):
+ self.httpd(8000, [Document])
+ rest = Resource('http://localhost:8000')
+
+ guid_1 = json.loads(
+ rest.post('/document', payload=json.dumps({
+ 'term': 'term',
+ 'stored': 'stored',
+ })).body_string()
+ )['guid']
+ guid_2 = json.loads(
+ rest.post('/document', payload=json.dumps({
+ 'term': 'term2',
+ 'stored': 'stored2',
+ 'vote': '1',
+ })).body_string()
+ )['guid']
+
+
+ reply = json.loads(rest.get('/document', reply='guid,stored,term,vote,counter').body_string())
+ self.assertEqual(2, reply['total'])
+ self.assertEqual(
+ sorted([{'guid': guid_1, 'stored': 'stored', 'term': 'term', 'vote': '0', 'counter': '0'},
+ {'guid': guid_2, 'stored': 'stored2', 'term': 'term2', 'vote': '1', 'counter': '1'},
+ ]),
+ sorted(reply['documents']))
+
+ self.httpdown(8000)
+ self.httpd(8000, [Document])
+
+ reply = json.loads(rest.get('/document', reply='guid,stored,term,vote,counter').body_string())
+ self.assertEqual(2, reply['total'])
+ self.assertEqual(
+ sorted([{'guid': guid_1, 'stored': 'stored', 'term': 'term', 'vote': '0', 'counter': '0'},
+ {'guid': guid_2, 'stored': 'stored2', 'term': 'term2', 'vote': '1', 'counter': '1'},
+ ]),
+ sorted(reply['documents']))
+
+
+class Resource(restkit.Resource):
+
+ def get(self, path=None, headers=None, **kwargs):
+ if headers is None:
+ headers = {}
+ if 'Content-Type' not in headers:
+ headers['Content-Type'] = 'application/json'
+ return restkit.Resource.get(self, path, headers=headers, **kwargs)
+
+ def put(self, path=None, headers=None, **kwargs):
+ if headers is None:
+ headers = {}
+ if 'Content-Type' not in headers:
+ headers['Content-Type'] = 'application/json'
+ return restkit.Resource.put(self, path, headers=headers, **kwargs)
+
+ def post(self, path=None, headers=None, **kwargs):
+ if headers is None:
+ headers = {}
+ if 'Content-Type' not in headers:
+ headers['Content-Type'] = 'application/json'
+ return restkit.Resource.post(self, path, headers=headers, **kwargs)
+
+ def delete(self, path=None, headers=None, **kwargs):
+ if headers is None:
+ headers = {}
+ if 'Content-Type' not in headers:
+ headers['Content-Type'] = 'application/json'
+ return restkit.Resource.delete(self, path, headers=headers, **kwargs)
+
if __name__ == '__main__':
tests.main()