(t *testing.T)
| 80 | } |
| 81 | |
| 82 | func TestConnectionReuse(t *testing.T) { |
| 83 | // Track unique connections |
| 84 | var connectionsMutex sync.Mutex |
| 85 | connections := make(map[string]bool) |
| 86 | requestCount := 0 |
| 87 | |
| 88 | // Create test server that tracks connections |
| 89 | server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 90 | connectionsMutex.Lock() |
| 91 | defer connectionsMutex.Unlock() |
| 92 | |
| 93 | // Track unique remote addresses (connections) |
| 94 | remoteAddr := r.RemoteAddr |
| 95 | connections[remoteAddr] = true |
| 96 | requestCount++ |
| 97 | |
| 98 | w.WriteHeader(http.StatusOK) |
| 99 | _, _ = w.Write([]byte(`{"status":"ok"}`)) |
| 100 | })) |
| 101 | defer server.Close() |
| 102 | |
| 103 | // Setup miniredis for queue |
| 104 | mr, err := miniredis.Run() |
| 105 | if err != nil { |
| 106 | t.Fatalf("an error '%s' occurred when starting miniredis", err) |
| 107 | } |
| 108 | defer mr.Close() |
| 109 | |
| 110 | // Configure with test server URL |
| 111 | cnf := &config.Configuration{ |
| 112 | Redis: config.RedisConfig{ |
| 113 | Dns: mr.Addr(), |
| 114 | }, |
| 115 | Queue: config.QueueConfig{ |
| 116 | WebhookQueue: "webhook_queue", |
| 117 | NumberOfQueues: 1, |
| 118 | }, |
| 119 | Notification: config.Notification{ |
| 120 | Webhook: config.WebhookConfig{ |
| 121 | Url: server.URL, |
| 122 | }, |
| 123 | }, |
| 124 | } |
| 125 | config.ConfigStore.Store(cnf) |
| 126 | |
| 127 | // Create LedgerForge instance |
| 128 | ledgerforge, err := NewLedgerForge(nil) |
| 129 | assert.NoError(t, err) |
| 130 | defer func() { _ = ledgerforge.Close() }() |
| 131 | |
| 132 | // Send multiple webhook requests directly (bypass queue for immediate testing) |
| 133 | numRequests := 10 |
| 134 | testWebhook := NewWebhook{ |
| 135 | Event: "transaction.applied", |
| 136 | Payload: map[string]interface{}{"test": "data"}, |
| 137 | } |
| 138 | |
| 139 | // Send multiple requests concurrently to test connection reuse |
nothing calls this directly
no test coverage detected