Skip to content

Commit 026036a

Browse files
committed
Proxy restore/race condition handling. Force ignore PROXY_MANUAL_START in internal tests
1 parent 7a59789 commit 026036a

File tree

7 files changed

+269
-138
lines changed

7 files changed

+269
-138
lines changed

sdk/internal/perf/recording_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,37 @@
44
package perf
55

66
import (
7+
"fmt"
78
"net/http"
9+
"os"
810
"regexp"
911
"testing"
1012

1113
"github.com/stretchr/testify/require"
14+
15+
"github.com/Azure/azure-sdk-for-go/sdk/internal/recording"
1216
)
1317

1418
func TestRecordingHTTPClient_Do(t *testing.T) {
19+
// Ignore manual start in pipeline tests, we always want to exercise install
20+
os.Setenv(recording.ProxyManualStartEnv, "false")
21+
22+
proxy, err := recording.StartTestProxy("", nil)
23+
require.NoError(t, err)
24+
defer func() {
25+
err := recording.StopTestProxy(proxy)
26+
if err != nil {
27+
panic(err)
28+
}
29+
}()
30+
1531
req, err := http.NewRequest("POST", "https://www.bing.com", nil)
1632
require.NoError(t, err)
1733

34+
proxyURL := fmt.Sprintf("https://localhost:%d", proxy.Options.ProxyPort)
1835
client := NewProxyTransport(&TransportOptions{
1936
TestName: t.Name(),
20-
proxyURL: "https://localhost:5001/",
37+
proxyURL: proxyURL,
2138
})
2239
require.NotNil(t, client)
2340

@@ -32,7 +49,7 @@ func TestRecordingHTTPClient_Do(t *testing.T) {
3249
require.NoError(t, err)
3350
resp, err = client.Do(req)
3451
require.NoError(t, err)
35-
require.Equal(t, "https://localhost:5001", resp.Request.URL.String())
52+
require.Equal(t, proxyURL, resp.Request.URL.String())
3653
require.Contains(t, resp.Request.Header.Get(upstreamURIHeader), "https://www.bing.com")
3754
require.Equal(t, resp.Request.Header.Get(modeHeader), "record")
3855
require.Equal(t, resp.Request.Header.Get(idHeader), client.recID)
@@ -42,7 +59,7 @@ func TestRecordingHTTPClient_Do(t *testing.T) {
4259
require.NoError(t, err)
4360
resp, err = client.Do(req)
4461
require.NoError(t, err)
45-
require.Equal(t, "https://localhost:5001", resp.Request.URL.String())
62+
require.Equal(t, proxyURL, resp.Request.URL.String())
4663
require.Contains(t, resp.Request.Header.Get(upstreamURIHeader), "https://www.bing.com")
4764
require.Equal(t, resp.Request.Header.Get(modeHeader), "playback")
4865
require.Equal(t, resp.Request.Header.Get(idHeader), client.recID)

sdk/internal/recording/matchers_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ func TestMatchers(t *testing.T) {
2626
}
2727

2828
func (s *matchersTests) SetupSuite() {
29-
proxy, err := StartTestProxy(nil)
29+
// Ignore manual start in pipeline tests, we always want to exercise install
30+
os.Setenv(ProxyManualStartEnv, "false")
31+
proxy, err := StartTestProxy("", nil)
3032
s.proxy = proxy
3133
require.NoError(s.T(), err)
3234
}

sdk/internal/recording/recording_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ func TestRecording(t *testing.T) {
3636
}
3737

3838
func (s *recordingTests) SetupSuite() {
39-
proxy, err := StartTestProxy(nil)
39+
// Ignore manual start in pipeline tests, we always want to exercise install
40+
os.Setenv(ProxyManualStartEnv, "false")
41+
proxy, err := StartTestProxy("", nil)
4042
s.proxy = proxy
4143
require.NoError(s.T(), err)
4244
}

sdk/internal/recording/sanitizer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestRecordingSanitizer(t *testing.T) {
3838
}
3939

4040
func (s *sanitizerTests) SetupSuite() {
41-
proxy, err := StartTestProxy(nil)
41+
proxy, err := StartTestProxy("", nil)
4242
s.proxy = proxy
4343
require.NoError(s.T(), err)
4444
}

0 commit comments

Comments
 (0)