(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func TestServer_MultipleConnections(t *testing.T) { |
| 233 | t.Parallel() |
| 234 | |
| 235 | socketPath := filepath.Join(testutil.TempDirUnixSocket(t), "boundary.sock") |
| 236 | srv := boundarylogproxy.NewServer(testutil.Logger(t), socketPath, prometheus.NewRegistry()) |
| 237 | |
| 238 | ctx, cancel := context.WithCancel(context.Background()) |
| 239 | defer cancel() |
| 240 | |
| 241 | err := srv.Start() |
| 242 | require.NoError(t, err) |
| 243 | t.Cleanup(func() { require.NoError(t, srv.Close()) }) |
| 244 | |
| 245 | reporter := &fakeReporter{} |
| 246 | |
| 247 | forwarderDone := make(chan error, 1) |
| 248 | go func() { |
| 249 | forwarderDone <- srv.RunForwarder(ctx, reporter) |
| 250 | }() |
| 251 | |
| 252 | // Create multiple connections and send from each. |
| 253 | const numConns = 3 |
| 254 | var wg sync.WaitGroup |
| 255 | wg.Add(numConns) |
| 256 | for i := range numConns { |
| 257 | go func(connID int) { |
| 258 | defer wg.Done() |
| 259 | conn, err := net.Dial("unix", socketPath) |
| 260 | if err != nil { |
| 261 | t.Errorf("conn %d dial: %s", connID, err) |
| 262 | } |
| 263 | defer conn.Close() |
| 264 | |
| 265 | req := &agentproto.ReportBoundaryLogsRequest{ |
| 266 | Logs: []*agentproto.BoundaryLog{ |
| 267 | { |
| 268 | Allowed: true, |
| 269 | Time: timestamppb.Now(), |
| 270 | Resource: &agentproto.BoundaryLog_HttpRequest_{ |
| 271 | HttpRequest: &agentproto.BoundaryLog_HttpRequest{ |
| 272 | Method: "GET", |
| 273 | Url: "https://example.com", |
| 274 | }, |
| 275 | }, |
| 276 | }, |
| 277 | }, |
| 278 | } |
| 279 | sendLogs(t, conn, req) |
| 280 | }(i) |
| 281 | } |
| 282 | wg.Wait() |
| 283 | |
| 284 | require.Eventually(t, func() bool { |
| 285 | logs := reporter.getLogs() |
| 286 | return len(logs) == numConns |
| 287 | }, testutil.WaitShort, testutil.IntervalFast) |
| 288 | |
| 289 | cancel() |
nothing calls this directly
no test coverage detected