You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

643 lines
25 KiB

  1. # -*- coding: utf-8 -*-
  2. import nilmdb.server
  3. import nilmdb.client
  4. from nilmdb.utils.printf import *
  5. from nilmdb.utils import timestamper
  6. from nilmdb.client import ClientError, ServerError
  7. from nilmdb.utils import datetime_tz
  8. from nose.plugins.skip import SkipTest
  9. from nose.tools import *
  10. from nose.tools import assert_raises
  11. import itertools
  12. import distutils.version
  13. import os
  14. import sys
  15. import threading
  16. import cStringIO
  17. import simplejson as json
  18. import unittest
  19. import warnings
  20. import resource
  21. import time
  22. import re
  23. from testutil.helpers import *
  24. testdb = "tests/client-testdb"
  25. testurl = "http://localhost:32180/"
  26. def setup_module():
  27. global test_server, test_db
  28. # Clear out DB
  29. recursive_unlink(testdb)
  30. # Start web app on a custom port
  31. test_db = nilmdb.utils.serializer_proxy(
  32. nilmdb.server.NilmDB)(testdb, sync = False)
  33. test_server = nilmdb.server.Server(test_db, host = "127.0.0.1",
  34. port = 32180, stoppable = False,
  35. fast_shutdown = True,
  36. force_traceback = True)
  37. test_server.start(blocking = False)
  38. def teardown_module():
  39. global test_server, test_db
  40. # Close web app
  41. test_server.stop()
  42. test_db.close()
  43. class TestClient(object):
  44. def test_client_01_basic(self):
  45. # Test a fake host
  46. client = nilmdb.client.Client(url = "http://localhost:1/")
  47. with assert_raises(nilmdb.client.ServerError):
  48. client.version()
  49. client.close()
  50. # Then a fake URL on a real host
  51. client = nilmdb.client.Client(url = "http://localhost:32180/fake/")
  52. with assert_raises(nilmdb.client.ClientError):
  53. client.version()
  54. client.close()
  55. # Now a real URL with no http:// prefix
  56. client = nilmdb.client.Client(url = "localhost:32180")
  57. version = client.version()
  58. client.close()
  59. # Now use the real URL
  60. client = nilmdb.client.Client(url = testurl)
  61. version = client.version()
  62. eq_(distutils.version.LooseVersion(version),
  63. distutils.version.LooseVersion(test_server.version))
  64. # Bad URLs should give 404, not 500
  65. with assert_raises(ClientError):
  66. client.http.get("/stream/create")
  67. client.close()
  68. def test_client_02_createlist(self):
  69. # Basic stream tests, like those in test_nilmdb:test_stream
  70. client = nilmdb.client.Client(url = testurl)
  71. # Database starts empty
  72. eq_(client.stream_list(), [])
  73. # Bad path
  74. with assert_raises(ClientError):
  75. client.stream_create("foo/bar/baz", "float32_8")
  76. with assert_raises(ClientError):
  77. client.stream_create("/foo", "float32_8")
  78. # Bad layout type
  79. with assert_raises(ClientError):
  80. client.stream_create("/newton/prep", "NoSuchLayout")
  81. # Bad method types
  82. with assert_raises(ClientError):
  83. client.http.put("/stream/list","")
  84. # Try a bunch of times to make sure the request body is getting consumed
  85. for x in range(10):
  86. with assert_raises(ClientError):
  87. client.http.post("/stream/list")
  88. client = nilmdb.client.Client(url = testurl)
  89. # Create three streams
  90. client.stream_create("/newton/prep", "float32_8")
  91. client.stream_create("/newton/raw", "uint16_6")
  92. client.stream_create("/newton/zzz/rawnotch", "uint16_9")
  93. # Verify we got 3 streams
  94. eq_(client.stream_list(), [ ["/newton/prep", "float32_8"],
  95. ["/newton/raw", "uint16_6"],
  96. ["/newton/zzz/rawnotch", "uint16_9"]
  97. ])
  98. # Match just one type or one path
  99. eq_(client.stream_list(layout="uint16_6"),
  100. [ ["/newton/raw", "uint16_6"] ])
  101. eq_(client.stream_list(path="/newton/raw"),
  102. [ ["/newton/raw", "uint16_6"] ])
  103. # Try messing with resource limits to trigger errors and get
  104. # more coverage. Here, make it so we can only create files 1
  105. # byte in size, which will trigger an IOError in the server when
  106. # we create a table.
  107. limit = resource.getrlimit(resource.RLIMIT_FSIZE)
  108. resource.setrlimit(resource.RLIMIT_FSIZE, (1, limit[1]))
  109. with assert_raises(ServerError) as e:
  110. client.stream_create("/newton/hello", "uint16_6")
  111. resource.setrlimit(resource.RLIMIT_FSIZE, limit)
  112. client.close()
  113. def test_client_03_metadata(self):
  114. client = nilmdb.client.Client(url = testurl)
  115. # Set / get metadata
  116. eq_(client.stream_get_metadata("/newton/prep"), {})
  117. eq_(client.stream_get_metadata("/newton/raw"), {})
  118. meta1 = { "description": "The Data",
  119. "v_scale": "1.234" }
  120. meta2 = { "description": "The Data" }
  121. meta3 = { "v_scale": "1.234" }
  122. client.stream_set_metadata("/newton/prep", meta1)
  123. client.stream_update_metadata("/newton/prep", {})
  124. client.stream_update_metadata("/newton/raw", meta2)
  125. client.stream_update_metadata("/newton/raw", meta3)
  126. eq_(client.stream_get_metadata("/newton/prep"), meta1)
  127. eq_(client.stream_get_metadata("/newton/raw"), meta1)
  128. eq_(client.stream_get_metadata("/newton/raw",
  129. [ "description" ] ), meta2)
  130. eq_(client.stream_get_metadata("/newton/raw",
  131. [ "description", "v_scale" ] ), meta1)
  132. # missing key
  133. eq_(client.stream_get_metadata("/newton/raw", "descr"),
  134. { "descr": None })
  135. eq_(client.stream_get_metadata("/newton/raw", [ "descr" ]),
  136. { "descr": None })
  137. # test wrong types (list instead of dict)
  138. with assert_raises(ClientError):
  139. client.stream_set_metadata("/newton/prep", [1,2,3])
  140. with assert_raises(ClientError):
  141. client.stream_update_metadata("/newton/prep", [1,2,3])
  142. # test wrong types (dict of non-strings)
  143. # numbers are OK; they'll get converted to strings
  144. client.stream_set_metadata("/newton/prep", { "hello": 1234 })
  145. # anything else is not
  146. with assert_raises(ClientError):
  147. client.stream_set_metadata("/newton/prep", { "world": { 1: 2 } })
  148. with assert_raises(ClientError):
  149. client.stream_set_metadata("/newton/prep", { "world": [ 1, 2 ] })
  150. client.close()
  151. def test_client_04_insert(self):
  152. client = nilmdb.client.Client(url = testurl)
  153. # Limit _max_data to 1 MB, since our test file is 1.5 MB
  154. old_max_data = nilmdb.client.client.StreamInserter._max_data
  155. nilmdb.client.client.StreamInserter._max_data = 1 * 1024 * 1024
  156. datetime_tz.localtz_set("America/New_York")
  157. testfile = "tests/data/prep-20120323T1000"
  158. start = datetime_tz.datetime_tz.smartparse("20120323T1000")
  159. start = start.totimestamp()
  160. rate = 120
  161. # First try a nonexistent path
  162. data = timestamper.TimestamperRate(testfile, start, 120)
  163. with assert_raises(ClientError) as e:
  164. result = client.stream_insert("/newton/no-such-path", data)
  165. in_("404 Not Found", str(e.exception))
  166. # Now try reversed timestamps
  167. data = timestamper.TimestamperRate(testfile, start, 120)
  168. data = reversed(list(data))
  169. with assert_raises(ClientError) as e:
  170. result = client.stream_insert("/newton/prep", data)
  171. in_("400 Bad Request", str(e.exception))
  172. in2_("timestamp is not monotonically increasing",
  173. "start must precede end", str(e.exception))
  174. # Now try empty data (no server request made)
  175. empty = cStringIO.StringIO("")
  176. data = timestamper.TimestamperRate(empty, start, 120)
  177. result = client.stream_insert("/newton/prep", data)
  178. eq_(result, None)
  179. # It's OK to insert an empty interval
  180. client.http.put("stream/insert", "", { "path": "/newton/prep",
  181. "start": 1, "end": 2 })
  182. eq_(list(client.stream_intervals("/newton/prep")), [[1, 2]])
  183. client.stream_remove("/newton/prep")
  184. eq_(list(client.stream_intervals("/newton/prep")), [])
  185. # Timestamps can be negative too
  186. client.http.put("stream/insert", "", { "path": "/newton/prep",
  187. "start": -2, "end": -1 })
  188. eq_(list(client.stream_intervals("/newton/prep")), [[-2, -1]])
  189. client.stream_remove("/newton/prep")
  190. eq_(list(client.stream_intervals("/newton/prep")), [])
  191. # Intervals that end at zero shouldn't be any different
  192. client.http.put("stream/insert", "", { "path": "/newton/prep",
  193. "start": -1, "end": 0 })
  194. eq_(list(client.stream_intervals("/newton/prep")), [[-1, 0]])
  195. client.stream_remove("/newton/prep")
  196. eq_(list(client.stream_intervals("/newton/prep")), [])
  197. # Try forcing a server request with equal start and end
  198. with assert_raises(ClientError) as e:
  199. client.http.put("stream/insert", "", { "path": "/newton/prep",
  200. "start": 0, "end": 0 })
  201. in_("400 Bad Request", str(e.exception))
  202. in_("start must precede end", str(e.exception))
  203. # Specify start/end (starts too late)
  204. data = timestamper.TimestamperRate(testfile, start, 120)
  205. with assert_raises(ClientError) as e:
  206. result = client.stream_insert("/newton/prep", data,
  207. start + 5, start + 120)
  208. in_("400 Bad Request", str(e.exception))
  209. in_("Data timestamp 1332511200.000000 < start time 1332511205.000000",
  210. str(e.exception))
  211. # Specify start/end (ends too early)
  212. data = timestamper.TimestamperRate(testfile, start, 120)
  213. with assert_raises(ClientError) as e:
  214. result = client.stream_insert("/newton/prep", data,
  215. start, start + 1)
  216. in_("400 Bad Request", str(e.exception))
  217. # Client chunks the input, so the exact timestamp here might change
  218. # if the chunk positions change.
  219. assert(re.search("Data timestamp 13325[0-9]+\.[0-9]+ "
  220. ">= end time 1332511201.000000", str(e.exception))
  221. is not None)
  222. # Now do the real load
  223. data = timestamper.TimestamperRate(testfile, start, 120)
  224. result = client.stream_insert("/newton/prep", data,
  225. start, start + 119.999777)
  226. # Verify the intervals. Should be just one, even if the data
  227. # was inserted in chunks, due to nilmdb interval concatenation.
  228. intervals = list(client.stream_intervals("/newton/prep"))
  229. eq_(intervals, [[start, start + 119.999777]])
  230. # Try some overlapping data -- just insert it again
  231. data = timestamper.TimestamperRate(testfile, start, 120)
  232. with assert_raises(ClientError) as e:
  233. result = client.stream_insert("/newton/prep", data)
  234. in_("400 Bad Request", str(e.exception))
  235. in_("verlap", str(e.exception))
  236. nilmdb.client.client.StreamInserter._max_data = old_max_data
  237. client.close()
  238. def test_client_05_extractremove(self):
  239. # Misc tests for extract and remove. Most of them are in test_cmdline.
  240. client = nilmdb.client.Client(url = testurl)
  241. for x in client.stream_extract("/newton/prep", 999123, 999124):
  242. raise AssertionError("shouldn't be any data for this request")
  243. with assert_raises(ClientError) as e:
  244. client.stream_remove("/newton/prep", 123, 120)
  245. # Test count
  246. eq_(client.stream_count("/newton/prep"), 14400)
  247. client.close()
  248. def test_client_06_generators(self):
  249. # A lot of the client functionality is already tested by test_cmdline,
  250. # but this gets a bit more coverage that cmdline misses.
  251. client = nilmdb.client.Client(url = testurl)
  252. # Trigger a client error in generator
  253. start = datetime_tz.datetime_tz.smartparse("20120323T2000")
  254. end = datetime_tz.datetime_tz.smartparse("20120323T1000")
  255. for function in [ client.stream_intervals, client.stream_extract ]:
  256. with assert_raises(ClientError) as e:
  257. function("/newton/prep",
  258. start.totimestamp(),
  259. end.totimestamp()).next()
  260. in_("400 Bad Request", str(e.exception))
  261. in_("start must precede end", str(e.exception))
  262. # Trigger a curl error in generator
  263. with assert_raises(ServerError) as e:
  264. client.http.get_gen("http://nosuchurl/").next()
  265. # Trigger a curl error in generator
  266. with assert_raises(ServerError) as e:
  267. client.http.get_gen("http://nosuchurl/").next()
  268. # Check 404 for missing streams
  269. for function in [ client.stream_intervals, client.stream_extract ]:
  270. with assert_raises(ClientError) as e:
  271. function("/no/such/stream").next()
  272. in_("404 Not Found", str(e.exception))
  273. in_("No such stream", str(e.exception))
  274. client.close()
  275. def test_client_07_headers(self):
  276. # Make sure that /stream/intervals and /stream/extract
  277. # properly return streaming, chunked, text/plain response.
  278. # Pokes around in client.http internals a bit to look at the
  279. # response headers.
  280. client = nilmdb.client.Client(url = testurl)
  281. http = client.http
  282. # Use a warning rather than returning a test failure for the
  283. # transfer-encoding, so that we can still disable chunked
  284. # responses for debugging.
  285. def headers():
  286. h = ""
  287. for (k, v) in http._last_response.headers.items():
  288. h += k + ": " + v + "\n"
  289. return h.lower()
  290. # Intervals
  291. x = http.get("stream/intervals", { "path": "/newton/prep" })
  292. if "transfer-encoding: chunked" not in headers():
  293. warnings.warn("Non-chunked HTTP response for /stream/intervals")
  294. if "content-type: application/x-json-stream" not in headers():
  295. raise AssertionError("/stream/intervals content type "
  296. "is not application/x-json-stream:\n" +
  297. headers())
  298. # Extract
  299. x = http.get("stream/extract",
  300. { "path": "/newton/prep",
  301. "start": "123",
  302. "end": "124" })
  303. if "transfer-encoding: chunked" not in headers():
  304. warnings.warn("Non-chunked HTTP response for /stream/extract")
  305. if "content-type: text/plain;charset=utf-8" not in headers():
  306. raise AssertionError("/stream/extract is not text/plain:\n" +
  307. headers())
  308. client.close()
  309. def test_client_08_unicode(self):
  310. # Try both with and without posting JSON
  311. for post_json in (False, True):
  312. # Basic Unicode tests
  313. client = nilmdb.client.Client(url = testurl, post_json = post_json)
  314. # Delete streams that exist
  315. for stream in client.stream_list():
  316. client.stream_destroy(stream[0])
  317. # Database is empty
  318. eq_(client.stream_list(), [])
  319. # Create Unicode stream, match it
  320. raw = [ u"/düsseldorf/raw", u"uint16_6" ]
  321. prep = [ u"/düsseldorf/prep", u"uint16_6" ]
  322. client.stream_create(*raw)
  323. eq_(client.stream_list(), [raw])
  324. eq_(client.stream_list(layout=raw[1]), [raw])
  325. eq_(client.stream_list(path=raw[0]), [raw])
  326. client.stream_create(*prep)
  327. eq_(client.stream_list(), [prep, raw])
  328. # Set / get metadata with Unicode keys and values
  329. eq_(client.stream_get_metadata(raw[0]), {})
  330. eq_(client.stream_get_metadata(prep[0]), {})
  331. meta1 = { u"alpha": u"α",
  332. u"β": u"beta" }
  333. meta2 = { u"alpha": u"α" }
  334. meta3 = { u"β": u"beta" }
  335. client.stream_set_metadata(prep[0], meta1)
  336. client.stream_update_metadata(prep[0], {})
  337. client.stream_update_metadata(raw[0], meta2)
  338. client.stream_update_metadata(raw[0], meta3)
  339. eq_(client.stream_get_metadata(prep[0]), meta1)
  340. eq_(client.stream_get_metadata(raw[0]), meta1)
  341. eq_(client.stream_get_metadata(raw[0], [ "alpha" ]), meta2)
  342. eq_(client.stream_get_metadata(raw[0], [ "alpha", "β" ]), meta1)
  343. client.close()
  344. def test_client_09_closing(self):
  345. # Make sure we actually close sockets correctly. New
  346. # connections will block for a while if they're not, since the
  347. # server will stop accepting new connections.
  348. for test in [1, 2]:
  349. start = time.time()
  350. for i in range(50):
  351. if time.time() - start > 15:
  352. raise AssertionError("Connections seem to be blocking... "
  353. "probably not closing properly.")
  354. if test == 1:
  355. # explicit close
  356. client = nilmdb.client.Client(url = testurl)
  357. with assert_raises(ClientError) as e:
  358. client.stream_remove("/newton/prep", 123, 120)
  359. client.close() # remove this to see the failure
  360. elif test == 2:
  361. # use the context manager
  362. with nilmdb.client.Client(url = testurl) as c:
  363. with assert_raises(ClientError) as e:
  364. c.stream_remove("/newton/prep", 123, 120)
  365. def test_client_10_context(self):
  366. # Test using the client's stream insertion context manager to
  367. # insert data.
  368. client = nilmdb.client.Client(testurl)
  369. client.stream_create("/context/test", "uint16_1")
  370. with client.stream_insert_context("/context/test") as ctx:
  371. # override _max_data to trigger frequent server updates
  372. ctx._max_data = 15
  373. ctx.insert("100 1\n")
  374. ctx.insert("101 ")
  375. ctx.insert("1\n102 1")
  376. ctx.insert("")
  377. ctx.insert("\n103 1\n")
  378. ctx.insert("104 1\n")
  379. ctx.insert("# hello\n")
  380. ctx.insert(" # hello\n")
  381. ctx.insert(" 105 1\n")
  382. ctx.finalize()
  383. ctx.insert("106 1\n")
  384. ctx.update_end(106.5)
  385. ctx.finalize()
  386. ctx.update_start(106.8)
  387. ctx.insert("107 1\n")
  388. ctx.insert("108 1\n")
  389. ctx.insert("109 1\n")
  390. ctx.insert("110 1\n")
  391. ctx.insert("111 1\n")
  392. ctx.update_end(113)
  393. ctx.insert("112 1\n")
  394. ctx.update_end(114)
  395. ctx.insert("113 1\n")
  396. ctx.update_end(115)
  397. ctx.insert("114 1" +
  398. " # this is super long" * 100 +
  399. "\n")
  400. ctx.finalize()
  401. ctx.insert("# this is super long" * 100)
  402. with assert_raises(ClientError):
  403. with client.stream_insert_context("/context/test", 100, 200) as ctx:
  404. ctx.insert("115 1\n")
  405. with assert_raises(ClientError):
  406. with client.stream_insert_context("/context/test", 200, 300) as ctx:
  407. ctx.insert("115 1\n")
  408. with assert_raises(ClientError):
  409. with client.stream_insert_context("/context/test") as ctx:
  410. ctx.insert("bogus data\n")
  411. with client.stream_insert_context("/context/test", 200, 300) as ctx:
  412. # make sure our override wasn't permanent
  413. ne_(ctx._max_data, 15)
  414. ctx.insert("225 1\n")
  415. ctx.finalize()
  416. with assert_raises(ClientError):
  417. with client.stream_insert_context("/context/test", 300, 400) as ctx:
  418. ctx.insert("301 1\n")
  419. ctx.insert("302 2\n")
  420. ctx.insert("303 3\n")
  421. ctx.insert("304 4\n")
  422. ctx.insert("304 4\n") # non-monotonic after a few lines
  423. ctx.finalize()
  424. eq_(list(client.stream_intervals("/context/test")),
  425. [ [ 100, 105.000001 ],
  426. [ 106, 106.5 ],
  427. [ 106.8, 115 ],
  428. [ 200, 300 ] ])
  429. client.stream_destroy("/context/test")
  430. client.close()
  431. def test_client_11_emptyintervals(self):
  432. # Empty intervals are ok! If recording detection events
  433. # by inserting rows into the database, we want to be able to
  434. # have an interval where no events occurred. Test them here.
  435. client = nilmdb.client.Client(testurl)
  436. client.stream_create("/empty/test", "uint16_1")
  437. def info():
  438. result = []
  439. for interval in list(client.stream_intervals("/empty/test")):
  440. result.append((client.stream_count("/empty/test", *interval),
  441. interval))
  442. return result
  443. eq_(info(), [])
  444. # Insert a region with just a few points
  445. with client.stream_insert_context("/empty/test") as ctx:
  446. ctx.update_start(100)
  447. ctx.insert("140 1\n")
  448. ctx.insert("150 1\n")
  449. ctx.insert("160 1\n")
  450. ctx.update_end(200)
  451. ctx.finalize()
  452. eq_(info(), [(3, [100, 200])])
  453. # Delete chunk, which will leave one data point and two intervals
  454. client.stream_remove("/empty/test", 145, 175)
  455. eq_(info(), [(1, [100, 145]),
  456. (0, [175, 200])])
  457. # Try also creating a completely empty interval from scratch,
  458. # in a few different ways.
  459. client.stream_insert("/empty/test", "", 300, 350)
  460. client.stream_insert("/empty/test", [], 400, 450)
  461. with client.stream_insert_context("/empty/test", 500, 550):
  462. pass
  463. # If enough timestamps aren't provided, empty streams won't be created.
  464. client.stream_insert("/empty/test", [])
  465. with client.stream_insert_context("/empty/test"):
  466. pass
  467. client.stream_insert("/empty/test", [], start = 600)
  468. with client.stream_insert_context("/empty/test", start = 700):
  469. pass
  470. client.stream_insert("/empty/test", [], end = 850)
  471. with client.stream_insert_context("/empty/test", end = 950):
  472. pass
  473. # Try various things that might cause problems
  474. with client.stream_insert_context("/empty/test", 1000, 1050):
  475. ctx.finalize() # inserts [1000, 1050]
  476. ctx.finalize() # nothing
  477. ctx.finalize() # nothing
  478. ctx.insert("1100 1\n")
  479. ctx.finalize() # inserts [1100, 1100.000001]
  480. ctx.update_start(1199)
  481. ctx.insert("1200 1\n")
  482. ctx.update_end(1250)
  483. ctx.finalize() # inserts [1199, 1250]
  484. ctx.update_start(1299)
  485. ctx.finalize() # nothing
  486. ctx.update_end(1350)
  487. ctx.finalize() # nothing
  488. ctx.update_start(1400)
  489. ctx.insert("# nothing!\n")
  490. ctx.update_end(1450)
  491. ctx.finalize()
  492. ctx.update_start(1500)
  493. ctx.insert("# nothing!")
  494. ctx.update_end(1550)
  495. ctx.finalize()
  496. ctx.insert("# nothing!\n" * 10)
  497. ctx.finalize()
  498. # implicit last finalize inserts [1400, 1450]
  499. # Check everything
  500. eq_(info(), [(1, [100, 145]),
  501. (0, [175, 200]),
  502. (0, [300, 350]),
  503. (0, [400, 450]),
  504. (0, [500, 550]),
  505. (0, [1000, 1050]),
  506. (1, [1100, 1100.000001]),
  507. (1, [1199, 1250]),
  508. (0, [1400, 1450]),
  509. (0, [1500, 1550]),
  510. ])
  511. # Clean up
  512. client.stream_destroy("/empty/test")
  513. client.close()
  514. def test_client_12_persistent(self):
  515. # Check that connections are persistent when they should be.
  516. # This is pretty hard to test; we have to poke deep into
  517. # the Requests library.
  518. with nilmdb.client.Client(url = testurl) as c:
  519. def connections():
  520. try:
  521. poolmanager = c.http._last_response.connection.poolmanager
  522. pool = poolmanager.pools[('http','localhost',32180)]
  523. return (pool.num_connections, pool.num_requests)
  524. except:
  525. raise SkipTest("can't get connection info")
  526. # First request makes a connection
  527. c.stream_create("/persist/test", "uint16_1")
  528. eq_(connections(), (1, 1))
  529. # Non-generator
  530. c.stream_list("/persist/test")
  531. eq_(connections(), (1, 2))
  532. c.stream_list("/persist/test")
  533. eq_(connections(), (1, 3))
  534. # Generators
  535. for x in c.stream_intervals("/persist/test"):
  536. pass
  537. eq_(connections(), (1, 4))
  538. for x in c.stream_intervals("/persist/test"):
  539. pass
  540. eq_(connections(), (1, 5))
  541. # Clean up
  542. c.stream_destroy("/persist/test")
  543. eq_(connections(), (1, 6))