MCPcopy
hub / github.com/nats-io/nats.go / TestListConsumers

Function TestListConsumers

jetstream/test/stream_test.go:1325–1402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1323}
1324
1325func TestListConsumers(t *testing.T) {
1326 tests := []struct {
1327 name string
1328 consumersNum int
1329 timeout time.Duration
1330 withError error
1331 }{
1332 {
1333 name: "list consumers",
1334 consumersNum: 500,
1335 timeout: 5 * time.Second,
1336 },
1337 {
1338 name: "with empty context",
1339 consumersNum: 500,
1340 },
1341 {
1342 name: "no consumers available",
1343 consumersNum: 0,
1344 },
1345 {
1346 name: "context timeout",
1347 consumersNum: 500,
1348 timeout: 1 * time.Microsecond,
1349 withError: context.DeadlineExceeded,
1350 },
1351 }
1352
1353 for _, test := range tests {
1354 t.Run(test.name, func(t *testing.T) {
1355 srv := RunBasicJetStreamServer()
1356 defer shutdownJSServerAndRemoveStorage(t, srv)
1357 nc, err := nats.Connect(srv.ClientURL())
1358 if err != nil {
1359 t.Fatalf("Unexpected error: %v", err)
1360 }
1361
1362 js, err := jetstream.New(nc)
1363 if err != nil {
1364 t.Fatalf("Unexpected error: %v", err)
1365 }
1366 defer nc.Close()
1367 s, err := js.CreateStream(context.Background(), jetstream.StreamConfig{Name: "foo", Subjects: []string{"FOO.*"}})
1368 if err != nil {
1369 t.Fatalf("Unexpected error: %v", err)
1370 }
1371 for i := 0; i < test.consumersNum; i++ {
1372 _, err = s.CreateOrUpdateConsumer(context.Background(), jetstream.ConsumerConfig{AckPolicy: jetstream.AckExplicitPolicy})
1373 if err != nil {
1374 t.Fatalf("Unexpected error: %v", err)
1375 }
1376 }
1377 ctx := context.Background()
1378 if test.timeout > 0 {
1379 var cancel context.CancelFunc
1380 ctx, cancel = context.WithTimeout(ctx, test.timeout)
1381 defer cancel()
1382 }

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
CreateStreamMethod · 0.65
ListConsumersMethod · 0.65
InfoMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.45
IsMethod · 0.45

Tested by

no test coverage detected