|
@@ -18,6 +18,7 @@ import simplejson as json |
|
|
import unittest |
|
|
import unittest |
|
|
import warnings |
|
|
import warnings |
|
|
import resource |
|
|
import resource |
|
|
|
|
|
import time |
|
|
|
|
|
|
|
|
from testutil.helpers import * |
|
|
from testutil.helpers import * |
|
|
|
|
|
|
|
@@ -101,8 +102,10 @@ class TestClient(object): |
|
|
["/newton/zzz/rawnotch", "RawNotchedData"] |
|
|
["/newton/zzz/rawnotch", "RawNotchedData"] |
|
|
]) |
|
|
]) |
|
|
# Match just one type or one path |
|
|
# Match just one type or one path |
|
|
eq_(client.stream_list(layout="RawData"), [ ["/newton/raw", "RawData"] ]) |
|
|
|
|
|
eq_(client.stream_list(path="/newton/raw"), [ ["/newton/raw", "RawData"] ]) |
|
|
|
|
|
|
|
|
eq_(client.stream_list(layout="RawData"), |
|
|
|
|
|
[ ["/newton/raw", "RawData"] ]) |
|
|
|
|
|
eq_(client.stream_list(path="/newton/raw"), |
|
|
|
|
|
[ ["/newton/raw", "RawData"] ]) |
|
|
|
|
|
|
|
|
# Try messing with resource limits to trigger errors and get |
|
|
# Try messing with resource limits to trigger errors and get |
|
|
# more coverage. Here, make it so we can only create files 1 |
|
|
# more coverage. Here, make it so we can only create files 1 |
|
@@ -131,9 +134,10 @@ class TestClient(object): |
|
|
client.stream_update_metadata("/newton/raw", meta3) |
|
|
client.stream_update_metadata("/newton/raw", meta3) |
|
|
eq_(client.stream_get_metadata("/newton/prep"), meta1) |
|
|
eq_(client.stream_get_metadata("/newton/prep"), meta1) |
|
|
eq_(client.stream_get_metadata("/newton/raw"), meta1) |
|
|
eq_(client.stream_get_metadata("/newton/raw"), meta1) |
|
|
eq_(client.stream_get_metadata("/newton/raw", [ "description" ] ), meta2) |
|
|
|
|
|
eq_(client.stream_get_metadata("/newton/raw", [ "description", |
|
|
|
|
|
"v_scale" ] ), meta1) |
|
|
|
|
|
|
|
|
eq_(client.stream_get_metadata("/newton/raw", |
|
|
|
|
|
[ "description" ] ), meta2) |
|
|
|
|
|
eq_(client.stream_get_metadata("/newton/raw", |
|
|
|
|
|
[ "description", "v_scale" ] ), meta1) |
|
|
|
|
|
|
|
|
# missing key |
|
|
# missing key |
|
|
eq_(client.stream_get_metadata("/newton/raw", "descr"), |
|
|
eq_(client.stream_get_metadata("/newton/raw", "descr"), |
|
@@ -356,3 +360,25 @@ class TestClient(object): |
|
|
eq_(client.stream_get_metadata(raw[0]), meta1) |
|
|
eq_(client.stream_get_metadata(raw[0]), meta1) |
|
|
eq_(client.stream_get_metadata(raw[0], [ "alpha" ]), meta2) |
|
|
eq_(client.stream_get_metadata(raw[0], [ "alpha" ]), meta2) |
|
|
eq_(client.stream_get_metadata(raw[0], [ "alpha", "β" ]), meta1) |
|
|
eq_(client.stream_get_metadata(raw[0], [ "alpha", "β" ]), meta1) |
|
|
|
|
|
|
|
|
|
|
|
def test_client_9_closing(self): |
|
|
|
|
|
# Make sure we actually close sockets correctly. New |
|
|
|
|
|
# connections will block for a while if they're not, since the |
|
|
|
|
|
# server will stop accepting new connections. |
|
|
|
|
|
for test in [1, 2]: |
|
|
|
|
|
start = time.time() |
|
|
|
|
|
for i in range(50): |
|
|
|
|
|
if time.time() - start > 15: |
|
|
|
|
|
raise AssertionError("Connections seem to be blocking... " |
|
|
|
|
|
"probably not closing properly.") |
|
|
|
|
|
if test == 1: |
|
|
|
|
|
# explicit close |
|
|
|
|
|
client = nilmdb.Client(url = "http://localhost:12380/") |
|
|
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
|
|
client.stream_remove("/newton/prep", 123, 120) |
|
|
|
|
|
client.close() # remove this to see the failure |
|
|
|
|
|
elif test == 2: |
|
|
|
|
|
# use the context manager |
|
|
|
|
|
with nilmdb.Client(url = "http://localhost:12380/") as c: |
|
|
|
|
|
with assert_raises(ClientError) as e: |
|
|
|
|
|
c.stream_remove("/newton/prep", 123, 120) |