-
Notifications
You must be signed in to change notification settings - Fork 174
/
test_js.py
827 lines (637 loc) · 24 KB
/
test_js.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
import asyncio
import http.client
import json
import ssl
import time
import unittest
import datetime
from unittest import mock
import tempfile
import shutil
import random
import nats
import nats.js.api
from nats.aio.client import Client as NATS
from nats.aio.client import __version__
from nats.errors import *
from nats.aio.errors import *
from nats.js.errors import *
from tests.utils import *
class PublishTest(SingleJetStreamServerTestCase):
@async_test
async def test_publish(self):
nc = NATS()
await nc.connect()
js = nc.jetstream()
with self.assertRaises(NoStreamResponseError):
await js.publish("foo", b'bar')
await js.add_stream(name="QUUX", subjects=["quux"])
ack = await js.publish("quux", b'bar:1', stream="QUUX")
self.assertEqual(ack.stream, "QUUX")
self.assertEqual(ack.seq, 1)
ack = await js.publish("quux", b'bar:2')
self.assertEqual(ack.stream, "QUUX")
self.assertEqual(ack.seq, 2)
with self.assertRaises(BadRequestError) as err:
await js.publish("quux", b'bar', stream="BAR")
self.assertEqual(err.exception.err_code, 10060)
await nc.close()
class PullSubscribeTest(SingleJetStreamServerTestCase):
@async_test
async def test_auto_create_consumer(self):
nc = NATS()
await nc.connect()
js = nc.jetstream()
sinfo = await js.add_stream(name="TEST2", subjects=["a2"])
sub = await js.pull_subscribe("a2", "auto")
await js.publish("a2", b'one')
msgs = await sub.fetch(1)
msg = msgs[0]
await msg.ack()
self.assertEqual(msg.data, b'one')
# Customize consumer config.
sub = await js.pull_subscribe(
"a2", "auto2", config=nats.js.api.ConsumerConfig(max_waiting=10)
)
msgs = await sub.fetch(1)
msg = msgs[0]
await msg.ack()
self.assertEqual(msg.data, b'one')
info = await js.consumer_info("TEST2", "auto2")
self.assertEqual(info.config.max_waiting, 10)
await nc.close()
await asyncio.sleep(1)
@async_test
async def test_fetch_one(self):
nc = NATS()
await nc.connect()
js = nc.jetstream()
sinfo = await js.add_stream(name="TEST1", subjects=["foo.1", "bar"])
# cinfo = await js.add_consumer(
# "TEST1", durable_name="dur", ack_policy=api.AckPolicy.explicit
# )
ack = await js.publish("foo.1", f'Hello from NATS!'.encode())
self.assertEqual(ack.stream, "TEST1")
self.assertEqual(ack.seq, 1)
# Bind to the consumer that is already present.
sub = await js.pull_subscribe("foo.1", "dur")
msgs = await sub.fetch(1)
for msg in msgs:
await msg.ack()
msg = msgs[0]
self.assertEqual(msg.metadata.sequence.stream, 1)
self.assertEqual(msg.metadata.sequence.consumer, 1)
self.assertTrue(datetime.datetime.now() > msg.metadata.timestamp)
self.assertEqual(msg.metadata.num_pending, 0)
self.assertEqual(msg.metadata.num_delivered, 1)
with self.assertRaises(asyncio.TimeoutError):
await sub.fetch(timeout=1)
for i in range(0, 10):
await js.publish(
"foo.1", f"i:{i}".encode(), headers={'hello': 'world'}
)
# nak
msgs = await sub.fetch()
msg = msgs[0]
# FIXME: This is failing with a Request Timeout error on CI
info = await js.consumer_info("TEST1", "dur", timeout=1)
self.assertEqual(msg.header, {'hello': 'world'})
await msg.nak()
info = await js.consumer_info("TEST1", "dur", timeout=1)
self.assertEqual(info.stream_name, "TEST1")
self.assertEqual(info.num_ack_pending, 1)
self.assertEqual(info.num_redelivered, 0)
# in_progress
msgs = await sub.fetch()
for msg in msgs:
await msg.in_progress()
# term
msgs = await sub.fetch()
for msg in msgs:
await msg.term()
info = await js.consumer_info("TEST1", "dur", timeout=1)
self.assertEqual(info.num_ack_pending, 1)
self.assertEqual(info.num_redelivered, 1)
await nc.close()
@async_test
async def test_fetch_max_waiting(self):
nc = NATS()
await nc.connect()
js = nc.jetstream()
await js.add_stream(name="TEST3", subjects=["max"])
sub = await js.pull_subscribe(
"max", "example", config={'max_waiting': 3}
)
results = None
try:
results = await asyncio.gather(
sub.fetch(1, timeout=1),
sub.fetch(1, timeout=1),
sub.fetch(1, timeout=1),
sub.fetch(1, timeout=1),
sub.fetch(1, timeout=1),
return_exceptions=True,
)
except:
pass
err = None
for e in results:
if isinstance(e, asyncio.TimeoutError):
continue
else:
self.assertIsInstance(e, APIError)
err = e
break
# Should get at least one Request Timeout error.
self.assertEqual(e.code, 408)
info = await js.consumer_info("TEST3", "example")
self.assertEqual(info.num_waiting, 3)
await nc.close()
class JSMTest(SingleJetStreamServerTestCase):
@async_test
async def test_stream_management(self):
nc = NATS()
await nc.connect()
jsm = nc.jsm()
acc = await jsm.account_info()
self.assertIsInstance(acc, nats.js.api.AccountInfo)
# Create stream
stream = await jsm.add_stream(
name="hello", subjects=["hello", "world", "hello.>"]
)
self.assertIsInstance(stream, nats.js.api.StreamInfo)
self.assertIsInstance(stream.config, nats.js.api.StreamConfig)
self.assertEqual(stream.config.name, "hello")
self.assertIsInstance(stream.state, nats.js.api.StreamState)
# Get info
current = await jsm.stream_info("hello")
stream.did_create = None
self.assertEqual(stream, current)
self.assertIsInstance(current, nats.js.api.StreamInfo)
self.assertIsInstance(current.config, nats.js.api.StreamConfig)
self.assertEqual(current.config.name, "hello")
self.assertIsInstance(current.state, nats.js.api.StreamState)
# Send messages
producer = nc.jetstream()
ack = await producer.publish('world', b'Hello world!')
self.assertEqual(ack.stream, "hello")
self.assertEqual(ack.seq, 1)
current = await jsm.stream_info("hello")
self.assertEqual(current.state.messages, 1)
self.assertEqual(current.state.bytes, 47)
# Delete stream
is_deleted = await jsm.delete_stream("hello")
self.assertTrue(is_deleted)
# Not foundError since there is none
with self.assertRaises(NotFoundError):
await jsm.stream_info("hello")
await nc.close()
@async_test
async def test_consumer_management(self):
nc = NATS()
await nc.connect()
jsm = nc.jsm()
acc = await jsm.account_info()
self.assertIsInstance(acc, nats.js.api.AccountInfo)
# Create stream.
await jsm.add_stream(name="ctests", subjects=["a", "b", "c.>"])
# Create durable consumer.
cinfo = await jsm.add_consumer(
"ctests",
durable_name="dur",
ack_policy="explicit",
)
# Fail with missing stream.
with self.assertRaises(NotFoundError) as err:
await jsm.consumer_info("missing", "c")
self.assertEqual(err.exception.err_code, 10059)
# Get consumer, there should be no changes.
current = await jsm.consumer_info("ctests", "dur")
self.assertEqual(cinfo, current)
# Delete consumer.
ok = await jsm.delete_consumer("ctests", "dur")
self.assertTrue(ok)
# Consumer lookup should not be 404 now.
with self.assertRaises(NotFoundError) as err:
await jsm.consumer_info("ctests", "dur")
self.assertEqual(err.exception.err_code, 10014)
# Create ephemeral consumer.
cinfo = await jsm.add_consumer(
"ctests",
ack_policy="explicit",
deliver_subject="asdf",
)
# Should not be empty.
self.assertTrue(len(cinfo.name) > 0)
ok = await jsm.delete_consumer("ctests", cinfo.name)
self.assertTrue(ok)
# Ephemeral no longer found after delete.
with self.assertRaises(NotFoundError):
await jsm.delete_consumer("ctests", cinfo.name)
await nc.close()
class SubscribeTest(SingleJetStreamServerTestCase):
@async_test
async def test_queue_subscribe_deliver_group(self):
nc = await nats.connect()
js = nc.jetstream()
await js.add_stream(name="qsub", subjects=["quux"])
a, b, c = ([], [], [])
async def cb1(msg):
a.append(msg)
async def cb2(msg):
b.append(msg)
async def cb3(msg):
c.append(msg)
subs = []
# First queue subscriber will create.
sub1 = await js.subscribe("quux", "wg", cb=cb1)
# Rest of queue subscribers will bind to the same.
sub2 = await js.subscribe("quux", "wg", cb=cb2)
sub3 = await js.subscribe("quux", "wg", cb=cb3)
# All should be bound to the same subject.
self.assertEqual(sub1.subject, sub2.subject)
self.assertEqual(sub1.subject, sub3.subject)
subs.append(sub1)
subs.append(sub2)
subs.append(sub3)
for i in range(100):
await js.publish("quux", f'Hello World {i}'.encode())
delivered = [a, b, c]
for i in range(5):
await asyncio.sleep(0.5)
total = len(a) + len(b) + len(c)
if total == 100:
break
# Check that there was a good balance among the group members.
self.assertEqual(len(a) + len(b) + len(c), 100)
for q in delivered:
self.assertTrue(10 <= len(q) <= 70)
# Now unsubscribe all.
await sub1.unsubscribe()
await sub2.drain()
await sub3.unsubscribe()
# Confirm that no more messages are received.
for i in range(200, 210):
await js.publish("quux", f'Hello World {i}'.encode())
with self.assertRaises(BadSubscriptionError):
await sub1.unsubscribe()
with self.assertRaises(BadSubscriptionError):
await sub2.drain()
await nc.close()
@async_test
async def test_subscribe_push_bound(self):
nc = await nats.connect()
js = nc.jetstream()
await js.add_stream(name="pbound", subjects=["pbound"])
a, b = ([], [])
async def cb1(msg):
a.append(msg)
async def cb2(msg):
b.append(msg)
subs = []
for i in range(10):
await js.publish("pbound", f'Hello World {i}'.encode())
# First subscriber will create.
sub1 = await js.subscribe("pbound", cb=cb1, durable="singleton")
await asyncio.sleep(0.5)
info = await js.consumer_info("pbound", "singleton")
self.assertTrue(info.push_bound)
# Rest of subscribers will not bind because it is already bound.
with self.assertRaises(nats.js.errors.Error) as err:
await js.subscribe("pbound", cb=cb2, durable="singleton")
self.assertEqual(
err.exception.description,
"consumer is already bound to a subscription"
)
with self.assertRaises(nats.js.errors.Error) as err:
await js.subscribe(
"pbound", queue="foo", cb=cb2, durable="singleton"
)
self.assertEqual(
err.exception.description,
"cannot create queue subscription 'foo' to consumer 'singleton'"
)
# Wait the delivery of the messages.
for i in range(5):
if len(a) == 10:
break
await asyncio.sleep(0.2)
self.assertEqual(len(a), 10)
# Create a sync subscriber now.
sub2 = await js.subscribe("pbound", durable="two")
msg = await sub2.next_msg()
self.assertEqual(msg.data, b'Hello World 0')
self.assertEqual(msg.metadata.sequence.stream, 1)
self.assertEqual(msg.metadata.sequence.consumer, 1)
self.assertEqual(sub2.pending_msgs, 9)
await nc.close()
@async_test
async def test_ephemeral_subscribe(self):
nc = await nats.connect()
js = nc.jetstream()
subject = "ephemeral"
await js.add_stream(name=subject, subjects=[subject])
for i in range(10):
await js.publish(subject, f'Hello World {i}'.encode())
# First subscriber will create.
sub1 = await js.subscribe(subject)
sub2 = await js.subscribe(subject)
recvd = 0
async for msg in sub1.messages:
recvd += 1
await msg.ack_sync()
if recvd == 10:
break
# Both should be able to process the messages at their own pace.
self.assertEqual(sub1.pending_msgs, 0)
self.assertEqual(sub2.pending_msgs, 10)
info1 = await sub1.consumer_info()
self.assertEqual(info1.stream_name, "ephemeral")
self.assertEqual(info1.num_ack_pending, 0)
self.assertTrue(len(info1.name) > 0)
info2 = await sub2.consumer_info()
self.assertEqual(info2.stream_name, "ephemeral")
self.assertEqual(info2.num_ack_pending, 10)
self.assertTrue(len(info2.name) > 0)
self.assertTrue(info1.name != info2.name)
class OrderedConsumerTest(SingleJetStreamServerTestCase):
@async_test
async def test_flow_control(self):
errors = []
async def error_handler(e):
print("Error:", e)
errors.append(e)
nc = await nats.connect(error_cb=error_handler)
js = nc.jetstream()
subject = "flow"
await js.add_stream(name=subject, subjects=[subject])
async def cb(msg):
await msg.ack()
with self.assertRaises(nats.js.errors.APIError) as err:
sub = await js.subscribe(subject, cb=cb, flow_control=True)
self.assertEqual(
err.exception.description,
"consumer with flow control also needs heartbeats"
)
sub = await js.subscribe(
subject, cb=cb, flow_control=True, idle_heartbeat=0.5
)
tasks = []
async def producer():
mlen = 128 * 1024
msg = b'A' * mlen
# Send it in chunks
i = 0
chunksize = 256
while i < mlen:
chunk = None
if mlen - i <= chunksize:
chunk = msg[i:]
else:
chunk = msg[i:i + chunksize]
i += chunksize
task = asyncio.create_task(js.publish(subject, chunk))
tasks.append(task)
task = asyncio.create_task(producer())
await asyncio.wait_for(task, timeout=1)
await asyncio.gather(*tasks)
for i in range(0, 5):
info = await sub.consumer_info()
await asyncio.sleep(0.5)
await nc.close()
@async_test
async def test_ordered_consumer(self):
errors = []
async def error_handler(e):
print("Error:", e)
errors.append(e)
nc = await nats.connect(error_cb=error_handler)
js = nc.jetstream()
subject = "osub"
await js.add_stream(name=subject, subjects=[subject], storage="memory")
msgs = []
async def cb(msg):
msgs.append(msg)
await msg.ack()
sub = await js.subscribe(
subject,
cb=cb,
ordered_consumer=True,
idle_heartbeat=0.3,
)
tasks = []
expected_size = 1048576
async def producer():
mlen = 1024 * 1024
msg = b'A' * mlen
# Send it in chunks
i = 0
chunksize = 1024
while i < mlen:
chunk = None
if mlen - i <= chunksize:
chunk = msg[i:]
else:
chunk = msg[i:i + chunksize]
i += chunksize
task = asyncio.create_task(
js.publish(subject, chunk, headers={'data': "true"})
)
await asyncio.sleep(0)
tasks.append(task)
task = asyncio.create_task(producer())
await asyncio.wait_for(task, timeout=4)
await asyncio.gather(*tasks)
self.assertEqual(len(msgs), 1024)
received_payload = bytearray(b'')
for msg in msgs:
received_payload.extend(msg.data)
self.assertEqual(len(received_payload), expected_size)
for i in range(0, 5):
info = await sub.consumer_info()
if info.num_pending == 0:
break
await asyncio.sleep(0.5)
info = await sub.consumer_info()
self.assertEqual(info.num_pending, 0)
await nc.close()
@async_long_test
async def test_ordered_consumer_single_loss(self):
errors = []
async def error_handler(e):
print("Error:", e)
errors.append(e)
# Consumer
nc = await nats.connect(error_cb=error_handler)
# Producer
nc2 = await nats.connect(error_cb=error_handler)
js = nc.jetstream()
js2 = nc2.jetstream()
# Consumer will lose some messages.
orig_build_message = nc._build_message
def _build_message(subject, reply, data, headers):
r = random.randint(0, 100)
if r <= 10 and headers and headers.get("data"):
nc._build_message = orig_build_message
return
return nc.msg_class(
subject=subject.decode(),
reply=reply.decode(),
data=data,
headers=headers,
client=nc
)
# Override to introduce arbitrary loss.
nc._build_message = _build_message
subject = "osub2"
await js2.add_stream(
name=subject, subjects=[subject], storage="memory"
)
# Consumer callback.
future = asyncio.Future()
msgs = []
async def cb(msg):
msgs.append(msg)
if len(msgs) >= 1024:
if not future.done():
future.set_result(True)
await msg.ack()
sub = await js.subscribe(
subject,
cb=cb,
ordered_consumer=True,
idle_heartbeat=0.3,
)
tasks = []
expected_size = 1048576
async def producer():
mlen = 1024 * 1024
msg = b'A' * mlen
# Send it in chunks
i = 0
chunksize = 1024
while i < mlen:
chunk = None
if mlen - i <= chunksize:
chunk = msg[i:]
else:
chunk = msg[i:i + chunksize]
i += chunksize
task = asyncio.create_task(
nc2.publish(subject, chunk, headers={'data': "true"})
)
tasks.append(task)
task = asyncio.create_task(producer())
await asyncio.wait_for(task, timeout=2)
await asyncio.gather(*tasks)
# Async publishing complete
await nc2.flush()
await asyncio.sleep(1)
# Wait until callback receives all the messages.
try:
await asyncio.wait_for(future, timeout=5)
except Exception as err:
print("Test Error:", err)
pass
self.assertEqual(len(msgs), 1024)
received_payload = bytearray(b'')
for msg in msgs:
received_payload.extend(msg.data)
self.assertEqual(len(received_payload), expected_size)
for i in range(0, 5):
info = await sub.consumer_info()
if info.num_pending == 0:
break
await asyncio.sleep(1)
info = await sub.consumer_info()
self.assertEqual(info.num_pending, 0)
await nc.close()
await nc2.close()
class KVTest(SingleJetStreamServerTestCase):
@async_test
async def test_kv_simple(self):
errors = []
async def error_handler(e):
print("Error:", e, type(e))
errors.append(e)
nc = await nats.connect(error_cb=error_handler)
js = nc.jetstream()
await js.add_stream(name="mystream")
kv = await js.create_key_value(bucket="TEST", history=5, ttl=3600)
status = await kv.status()
self.assertEqual(status.bucket, "TEST")
self.assertEqual(status.values, 0)
self.assertEqual(status.history, 5)
self.assertEqual(int(status.ttl), 3600)
seq = await kv.put("hello", b'world')
self.assertEqual(seq, 1)
entry = await kv.get("hello")
self.assertEqual("hello", entry.key)
self.assertEqual(b'world', entry.value)
status = await kv.status()
self.assertEqual(status.values, 1)
for i in range(0, 100):
await kv.put(f"hello.{i}", b'Hello JS KV!')
status = await kv.status()
self.assertEqual(status.values, 101)
await kv.delete("hello.1")
with self.assertRaises(KeyDeletedError) as err:
await kv.get("hello.1")
self.assertEqual(err.exception.entry.key, 'hello.1')
self.assertEqual(err.exception.entry.revision, 102)
self.assertEqual(err.exception.entry.value, None)
self.assertEqual(err.exception.op, 'DEL')
await kv.purge("hello.5")
with self.assertRaises(KeyDeletedError) as err:
await kv.get("hello.5")
self.assertEqual(err.exception.entry.key, 'hello.5')
self.assertEqual(err.exception.entry.revision, 103)
self.assertEqual(err.exception.entry.value, None)
self.assertEqual(err.exception.op, 'PURGE')
status = await kv.status()
self.assertEqual(status.values, 102)
await kv.purge("hello.*")
with self.assertRaises(NotFoundError):
await kv.get("hello.5")
status = await kv.status()
self.assertEqual(status.values, 2)
entry = await kv.get("hello")
self.assertEqual("hello", entry.key)
self.assertEqual(b'world', entry.value)
self.assertEqual(1, entry.revision)
# Now get the the same KV via lookup.
kv = await js.key_value("TEST")
entry = await kv.get("hello")
self.assertEqual("hello", entry.key)
self.assertEqual(b'world', entry.value)
self.assertEqual(1, entry.revision)
status = await kv.status()
self.assertEqual(status.values, 2)
for i in range(100, 200):
await kv.put(f"hello.{i}", b'Hello JS KV!')
status = await kv.status()
self.assertEqual(status.values, 102)
with self.assertRaises(NotFoundError):
await kv.get("hello.5")
entry = await kv.get("hello.102")
self.assertEqual("hello.102", entry.key)
self.assertEqual(b'Hello JS KV!', entry.value)
self.assertEqual(107, entry.revision)
await nc.close()
@async_test
async def test_not_kv(self):
errors = []
async def error_handler(e):
print("Error:", e, type(e))
errors.append(e)
nc = await nats.connect(error_cb=error_handler)
js = nc.jetstream()
with self.assertRaises(BucketNotFoundError):
await js.key_value(bucket="TEST2")
await js.add_stream(name="KV_TEST3")
with self.assertRaises(BadBucketError):
await js.key_value(bucket="TEST3")
if __name__ == '__main__':
import sys
runner = unittest.TextTestRunner(stream=sys.stdout)
unittest.main(verbosity=2, exit=False, testRunner=runner)