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

Function TestEndpointPendingLimits

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

Source from the content-addressed store, hash-verified

1912}
1913
1914func TestEndpointPendingLimits(t *testing.T) {
1915 s := RunServerOnPort(-1)
1916 defer s.Shutdown()
1917
1918 nc, err := nats.Connect(s.ClientURL())
1919 if err != nil {
1920 t.Fatalf("Error connecting to server: %v", err)
1921 }
1922 defer nc.Close()
1923
1924 handler := micro.HandlerFunc(func(req micro.Request) {
1925 time.Sleep(10 * time.Millisecond)
1926 req.Respond([]byte("OK"))
1927 })
1928
1929 t.Run("with pending limits", func(t *testing.T) {
1930 srv, err := micro.AddService(nc, micro.Config{
1931 Name: "test-service",
1932 Version: "1.0.0",
1933 })
1934 if err != nil {
1935 t.Fatalf("Error adding service: %v", err)
1936 }
1937 defer srv.Stop()
1938
1939 msgLimit := 10
1940 bytesLimit := 1024
1941
1942 err = srv.AddEndpoint("test", handler,
1943 micro.WithEndpointSubject("test.pending"),
1944 micro.WithEndpointPendingLimits(msgLimit, bytesLimit))
1945 if err != nil {
1946 t.Fatalf("Error adding endpoint: %v", err)
1947 }
1948
1949 // Verify endpoint was created
1950 info := srv.Info()
1951 if len(info.Endpoints) != 1 {
1952 t.Fatalf("Expected 1 endpoint, got %d", len(info.Endpoints))
1953 }
1954
1955 // Send messages and verify they're handled
1956 for i := range 5 {
1957 resp, err := nc.Request("test.pending", []byte("test"), 100*time.Millisecond)
1958 if err != nil {
1959 t.Fatalf("Error on request %d: %v", i, err)
1960 }
1961 if string(resp.Data) != "OK" {
1962 t.Fatalf("Expected OK response, got %s", string(resp.Data))
1963 }
1964 }
1965 })
1966
1967 t.Run("with only msg limit", func(t *testing.T) {
1968 srv, err := micro.AddService(nc, micro.Config{
1969 Name: "test-service-msg-only",
1970 Version: "1.0.0",
1971 })

Callers

nothing calls this directly

Calls 15

HandlerFuncFuncType · 0.92
AddServiceFunction · 0.92
WithEndpointSubjectFunction · 0.92
ConnectMethod · 0.80
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
RespondMethod · 0.65
StopMethod · 0.65
AddEndpointMethod · 0.65
InfoMethod · 0.65
PublishMethod · 0.65

Tested by

no test coverage detected