(ctx context.Context, numNodes int, cfg *proxyTestConfig)
| 427 | } |
| 428 | |
| 429 | func setupProxyTestWithConfig(ctx context.Context, numNodes int, cfg *proxyTestConfig) (tester *proxyTester, proxyContactPoint string, err error) { |
| 430 | tester = &proxyTester{ |
| 431 | wg: sync.WaitGroup{}, |
| 432 | } |
| 433 | |
| 434 | clusterPort, clusterAddr, proxyAddr, _ := generateTestAddrs(testAddr) |
| 435 | |
| 436 | tester.cluster = proxycore.NewMockCluster(net.ParseIP(testStartAddr), clusterPort) |
| 437 | tester.cluster.DseVersion = cfg.dseVersion |
| 438 | |
| 439 | if cfg == nil { |
| 440 | cfg = &proxyTestConfig{} |
| 441 | } |
| 442 | |
| 443 | if cfg.handlers != nil { |
| 444 | tester.cluster.Handlers = proxycore.NewMockRequestHandlers(cfg.handlers) |
| 445 | } |
| 446 | |
| 447 | for i := 1; i <= numNodes; i++ { |
| 448 | err = tester.cluster.Add(ctx, i) |
| 449 | if err != nil { |
| 450 | return tester, proxyAddr, err |
| 451 | } |
| 452 | } |
| 453 | tester.proxy = NewProxy(ctx, Config{ |
| 454 | Version: primitive.ProtocolVersion4, |
| 455 | Resolver: proxycore.NewResolverWithDefaultPort([]string{clusterAddr}, clusterPort), |
| 456 | ReconnectPolicy: proxycore.NewReconnectPolicyWithDelays(200*time.Millisecond, time.Second), |
| 457 | NumConns: 2, |
| 458 | HeartBeatInterval: 30 * time.Second, |
| 459 | ConnectTimeout: 10 * time.Second, |
| 460 | IdleTimeout: 60 * time.Second, |
| 461 | RPCAddr: cfg.rpcAddr, |
| 462 | Peers: cfg.peers, |
| 463 | IdempotentGraph: cfg.idempotentGraph, |
| 464 | Logger: zap.L(), |
| 465 | }) |
| 466 | |
| 467 | err = tester.proxy.Connect() |
| 468 | if err != nil { |
| 469 | return tester, proxyAddr, err |
| 470 | } |
| 471 | |
| 472 | l, err := resolveAndListen(proxyAddr, "", "") |
| 473 | if err != nil { |
| 474 | return tester, proxyAddr, err |
| 475 | } |
| 476 | |
| 477 | tester.wg.Add(1) |
| 478 | |
| 479 | go func() { |
| 480 | _ = tester.proxy.Serve(l) |
| 481 | tester.wg.Done() |
| 482 | }() |
| 483 | |
| 484 | return tester, proxyAddr, nil |
| 485 | } |
| 486 |
no test coverage detected