MCPcopy Create free account
hub / github.com/erpc/erpc / TestHttpServer_RaceTimeouts

Function TestHttpServer_RaceTimeouts

erpc/http_server_test.go:40–480  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38)
39
40func TestHttpServer_RaceTimeouts(t *testing.T) {
41 t.Run("ConcurrentRequestsWithTimeouts", func(t *testing.T) {
42 util.ResetGock()
43 defer util.ResetGock()
44 gock.EnableNetworking()
45 gock.NetworkingFilter(func(req *http.Request) bool {
46 shouldMakeRealCall := strings.Split(req.URL.Host, ":")[0] == "localhost"
47 return shouldMakeRealCall
48 })
49 util.SetupMocksForEvmStatePoller()
50 defer util.AssertNoPendingMocks(t, 0)
51
52 gock.New("http://rpc1.localhost").
53 Post("/").
54 Times(50).
55 Reply(200).
56 Delay(2000 * time.Millisecond). // Delay longer than the server timeout
57 JSON(map[string]interface{}{
58 "jsonrpc": "2.0",
59 "id": 1,
60 "result": "0x222222",
61 })
62
63 // Setup
64 logger := log.Logger
65 ctx, cancel := context.WithCancel(context.Background())
66 defer cancel()
67
68 cfg := &common.Config{
69 Server: &common.ServerConfig{
70 MaxTimeout: common.Duration(500 * time.Millisecond).Ptr(), // Set a very short timeout for testing
71 ListenV4: util.BoolPtr(true), // Explicitly enable IPv4 for test
72 },
73 Projects: []*common.ProjectConfig{
74 {
75 Id: "test_project",
76 Networks: []*common.NetworkConfig{
77 {
78 Architecture: common.ArchitectureEvm,
79 Evm: &common.EvmNetworkConfig{
80 ChainId: 123,
81 },
82 },
83 },
84 Upstreams: []*common.UpstreamConfig{
85 {
86 Type: common.UpstreamTypeEvm,
87 Endpoint: "http://rpc1.localhost",
88 Evm: &common.EvmUpstreamConfig{
89 ChainId: 123,
90 },
91 },
92 },
93 },
94 },
95 RateLimiters: &common.RateLimiterConfig{},
96 }
97

Callers

nothing calls this directly

Calls 15

BootstrapMethod · 0.95
ResetGockFunction · 0.92
AssertNoPendingMocksFunction · 0.92
DurationTypeAlias · 0.92
BoolPtrFunction · 0.92
NewSharedStateRegistryFunction · 0.92
NewERPCFunction · 0.85
NewHttpServerFunction · 0.85
PtrMethod · 0.80
AddrMethod · 0.80
ServeMethod · 0.80

Tested by

no test coverage detected