MCPcopy
hub / github.com/cloudflare/cloudflared / TestPersistentConnection

Function TestPersistentConnection

orchestration/orchestrator_test.go:664–778  ·  view source on GitHub ↗

TestPersistentConnection makes sure updating the ingress doesn't intefere with existing connections

(t *testing.T)

Source from the content-addressed store, hash-verified

662
663// TestPersistentConnection makes sure updating the ingress doesn't intefere with existing connections
664func 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

Callers

nothing calls this directly

Calls 15

GetOriginProxyMethod · 0.95
NewOriginDialerFunction · 0.92
NewHTTP2RespWriterFunction · 0.92
NewTracedHTTPRequestFunction · 0.92
NewOrchestratorFunction · 0.85
updateWithValidationFunction · 0.85
newRespReadWriteFlusherFunction · 0.85
echoTCPFunction · 0.85
proxyTCPFunction · 0.85
validateWsEchoFunction · 0.85
tcpEyeballFunction · 0.85
AddrMethod · 0.80

Tested by

no test coverage detected