TestPersistentConnection makes sure updating the ingress doesn't intefere with existing connections
(t *testing.T)
| 662 | |
| 663 | // TestPersistentConnection makes sure updating the ingress doesn't intefere with existing connections |
| 664 | func TestPersistentConnection(t *testing.T) { |
| 665 | const ( |
| 666 | hostname = "http://ws.tunnel.org" |
| 667 | ) |
| 668 | msg := t.Name() |
| 669 | originDialer := ingress.NewOriginDialer(ingress.OriginConfig{ |
| 670 | DefaultDialer: testDefaultDialer, |
| 671 | TCPWriteTimeout: 1 * time.Second, |
| 672 | }, &testLogger) |
| 673 | initConfig := &Config{ |
| 674 | Ingress: &ingress.Ingress{}, |
| 675 | OriginDialerService: originDialer, |
| 676 | } |
| 677 | orchestrator, err := NewOrchestrator(t.Context(), initConfig, testTags, []ingress.Rule{}, &testLogger) |
| 678 | require.NoError(t, err) |
| 679 | |
| 680 | wsOrigin := httptest.NewServer(http.HandlerFunc(wsEcho)) |
| 681 | defer wsOrigin.Close() |
| 682 | |
| 683 | tcpOrigin, err := net.Listen("tcp", "127.0.0.1:0") |
| 684 | require.NoError(t, err) |
| 685 | defer tcpOrigin.Close() |
| 686 | |
| 687 | configWithWSAndWarp := []byte(fmt.Sprintf(` |
| 688 | { |
| 689 | "ingress": [ |
| 690 | { |
| 691 | "service": "%s" |
| 692 | } |
| 693 | ], |
| 694 | "warp-routing": { |
| 695 | } |
| 696 | } |
| 697 | `, wsOrigin.URL)) |
| 698 | |
| 699 | updateWithValidation(t, orchestrator, 1, configWithWSAndWarp) |
| 700 | |
| 701 | originProxy, err := orchestrator.GetOriginProxy() |
| 702 | require.NoError(t, err) |
| 703 | |
| 704 | wsReqReader, wsReqWriter := io.Pipe() |
| 705 | wsRespReadWriter := newRespReadWriteFlusher() |
| 706 | |
| 707 | tcpReqReader, tcpReqWriter := io.Pipe() |
| 708 | tcpRespReadWriter := newRespReadWriteFlusher() |
| 709 | |
| 710 | ctx, cancel := context.WithCancel(t.Context()) |
| 711 | defer cancel() |
| 712 | |
| 713 | var wg sync.WaitGroup |
| 714 | wg.Add(3) |
| 715 | // Start TCP origin |
| 716 | go func() { |
| 717 | defer wg.Done() |
| 718 | conn, err := tcpOrigin.Accept() |
| 719 | assert.NoError(t, err) |
| 720 | defer conn.Close() |
| 721 |
nothing calls this directly
no test coverage detected