Skip to content

Commit

Permalink
Proxy restore/race condition handling. Force ignore PROXY_MANUAL_STAR…
Browse files Browse the repository at this point in the history
…T in internal tests
  • Loading branch information
benbp committed Jul 20, 2023
1 parent 7a59789 commit ee6260d
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 138 deletions.
23 changes: 20 additions & 3 deletions sdk/internal/perf/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
package perf

import (
"fmt"
"net/http"
"os"
"regexp"
"testing"

"github.com/stretchr/testify/require"

"github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
)

func TestRecordingHTTPClient_Do(t *testing.T) {
// Ignore manual start in pipeline tests, we always want to exercise install
os.Setenv(recording.ProxyManualStartEnv, "false")

proxy, err := recording.StartTestProxy("", nil)
require.NoError(t, err)
defer func() {
err := recording.StopTestProxy(proxy)
if err != nil {
panic(err)
}
}()

req, err := http.NewRequest("POST", "https://www.bing.com", nil)
require.NoError(t, err)

proxyURL := fmt.Sprintf("https://localhost:%d", proxy.Options.ProxyPort)
client := NewProxyTransport(&TransportOptions{
TestName: t.Name(),
proxyURL: "https://localhost:5001/",
proxyURL: proxyURL,
})
require.NotNil(t, client)

Expand All @@ -32,7 +49,7 @@ func TestRecordingHTTPClient_Do(t *testing.T) {
require.NoError(t, err)
resp, err = client.Do(req)
require.NoError(t, err)
require.Equal(t, "https://localhost:5001", resp.Request.URL.String())
require.Equal(t, proxyURL, resp.Request.URL.String())
require.Contains(t, resp.Request.Header.Get(upstreamURIHeader), "https://www.bing.com")
require.Equal(t, resp.Request.Header.Get(modeHeader), "record")
require.Equal(t, resp.Request.Header.Get(idHeader), client.recID)
Expand All @@ -42,7 +59,7 @@ func TestRecordingHTTPClient_Do(t *testing.T) {
require.NoError(t, err)
resp, err = client.Do(req)
require.NoError(t, err)
require.Equal(t, "https://localhost:5001", resp.Request.URL.String())
require.Equal(t, proxyURL, resp.Request.URL.String())
require.Contains(t, resp.Request.Header.Get(upstreamURIHeader), "https://www.bing.com")
require.Equal(t, resp.Request.Header.Get(modeHeader), "playback")
require.Equal(t, resp.Request.Header.Get(idHeader), client.recID)
Expand Down
4 changes: 3 additions & 1 deletion sdk/internal/recording/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func TestMatchers(t *testing.T) {
}

func (s *matchersTests) SetupSuite() {
proxy, err := StartTestProxy(nil)
// Ignore manual start in pipeline tests, we always want to exercise install
os.Setenv(ProxyManualStartEnv, "false")
proxy, err := StartTestProxy("", nil)
s.proxy = proxy
require.NoError(s.T(), err)
}
Expand Down
4 changes: 3 additions & 1 deletion sdk/internal/recording/recording_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func TestRecording(t *testing.T) {
}

func (s *recordingTests) SetupSuite() {
proxy, err := StartTestProxy(nil)
// Ignore manual start in pipeline tests, we always want to exercise install
os.Setenv(ProxyManualStartEnv, "false")
proxy, err := StartTestProxy("", nil)
s.proxy = proxy
require.NoError(s.T(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/internal/recording/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRecordingSanitizer(t *testing.T) {
}

func (s *sanitizerTests) SetupSuite() {
proxy, err := StartTestProxy(nil)
proxy, err := StartTestProxy("", nil)
s.proxy = proxy
require.NoError(s.T(), err)
}
Expand Down
Loading

0 comments on commit ee6260d

Please sign in to comment.