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

Function TestCustomQueueGroup

micro/test/service_test.go:1507–1804  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1505}
1506
1507func TestCustomQueueGroup(t *testing.T) {
1508 tests := []struct {
1509 name string
1510 endpointInit func(*testing.T, *nats.Conn) micro.Service
1511 expectedQueueGroups map[string]string
1512 }{
1513 {
1514 name: "default queue group",
1515 endpointInit: func(t *testing.T, nc *nats.Conn) micro.Service {
1516 srv, err := micro.AddService(nc, micro.Config{
1517 Name: "test_service",
1518 Version: "0.0.1",
1519 Endpoint: &micro.EndpointConfig{
1520 Subject: "foo",
1521 Handler: micro.HandlerFunc(func(r micro.Request) {}),
1522 },
1523 })
1524 if err != nil {
1525 t.Fatalf("Unexpected error: %v", err)
1526 }
1527 err = srv.AddEndpoint("bar", micro.HandlerFunc(func(r micro.Request) {}))
1528 if err != nil {
1529 t.Fatalf("Unexpected error: %v", err)
1530 }
1531 return srv
1532 },
1533 expectedQueueGroups: map[string]string{
1534 "default": "q",
1535 "bar": "q",
1536 },
1537 },
1538 {
1539 name: "custom queue group on service config",
1540 endpointInit: func(t *testing.T, nc *nats.Conn) micro.Service {
1541 srv, err := micro.AddService(nc, micro.Config{
1542 Name: "test_service",
1543 Version: "0.0.1",
1544 QueueGroup: "custom",
1545 Endpoint: &micro.EndpointConfig{
1546 Subject: "foo",
1547 Handler: micro.HandlerFunc(func(r micro.Request) {}),
1548 },
1549 })
1550 if err != nil {
1551 t.Fatalf("Unexpected error: %v", err)
1552 }
1553
1554 // add endpoint on service directly, should have the same queue group
1555 err = srv.AddEndpoint("bar", micro.HandlerFunc(func(r micro.Request) {}))
1556 if err != nil {
1557 t.Fatalf("Unexpected error: %v", err)
1558 }
1559
1560 // add group with queue group from service config
1561 g1 := srv.AddGroup("g1")
1562
1563 // add endpoint on group, should have queue group from service config
1564 err = g1.AddEndpoint("baz", micro.HandlerFunc(func(r micro.Request) {}))

Callers

nothing calls this directly

Calls 15

AddServiceFunction · 0.92
HandlerFuncFuncType · 0.92
WithEndpointQueueGroupFunction · 0.92
WithGroupQueueGroupFunction · 0.92
FatalfMethod · 0.80
ConnectMethod · 0.80
RunServerOnPortFunction · 0.70
AddEndpointMethod · 0.65
AddGroupMethod · 0.65
StopMethod · 0.65
InfoMethod · 0.65

Tested by

no test coverage detected