Skip to content

Instantly share code, notes, and snippets.

@semick-dev
Last active July 10, 2024 18:40
Show Gist options
  • Save semick-dev/40b130c0b1f8b9a36548002a4cf6c3eb to your computer and use it in GitHub Desktop.
Save semick-dev/40b130c0b1f8b9a36548002a4cf6c3eb to your computer and use it in GitHub Desktop.
How does one debug a test-proxy session?

How to debug test-proxy issues

This writeup is NOT a reference on how to install or run the test-proxy, it is a shortcut guide to helping a test-proxy dev debug each language's tests.

.NET

To run storage tests, azurite must be installed

  1. Install npm, ensure node is available on PATH
  2. Install npm version of azurite, npm install -g azurite
  3. Set environment variable AZURE_AZURITE_LOCATION to the location of your npm root -g output
    • For me this was C:/.tools/.npm-global/

Run the tests

  1. Set environment variable PROXY_DEBUG_MODE to true.
    • Optionally, opening up TestProxy.cs, scrolling down the TestProxy startup, and setting debugMode = true will ensure that it always runs with traffic directed at 5000/5001.
  2. Start the debugging proxy instance
  3. Open VS2022 and then the targeted .NET solution
    • Open VS2022 after running New-TestResources and setting the environment variables in a CLI instance, then open vs manually from there.
    • That is C:/Program Files/Microsoft Visual Studio/2022/Enterprise/Common7/IDE/devenv.exe for me.
  4. Debug whichever tests by right click -> debug, it'll route to your running proxy.

Python

  1. Set environment variable PROXY_MANUAL_START to true
  • If you wish to fiddle or otherwise intercept the traffic, using PROXY_URL=http://localhost:5000 is a good idea.
  1. Start the debugging proxy instance
    • --storage-location=/path/to/target/repo/root
  2. Debug python tests as normal

Go

  1. Set the environment variable PROXY_MANUAL_START to true
  2. Run the prxoy in selected mode
  3. go to targeted directory, go build
  4. Invoke tests go test
  • go test -run TestClient_GetManifest

For livetests, if there is NO test-resources.json, DO NOT DESPAIR. To successfully invoke livetests in in record mode, I set the following env variables (for sdk/containers/azcontainerregistry), which can be obtained by:

.\eng\common\TestResources\New-TestResources.ps1 containers/azcontainerregistry -UserAuth

${env:REGISTRY_NAME} = '<blahblah>'
${env:AZCONTAINERREGISTRY_RESOURCE_GROUP} = '<my-rg>'
${env:LOGIN_SERVER} = '<blahblah>.azurecr.io'
${env:AZURE_SERVICE_DIRECTORY} = 'AZCONTAINERREGISTRY'
${env:AZCONTAINERREGISTRY_RESOURCE_MANAGER_URL} = 'https://management.azure.com/'
${env:AZCONTAINERREGISTRY_SUBSCRIPTION_ID} = '<subid>'
${env:AZCONTAINERREGISTRY_AZURE_AUTHORITY_HOST} = 'https://login.microsoftonline.com/'
${env:AZCONTAINERREGISTRY_LOCATION} = '<region>'
${env:AZCONTAINERREGISTRY_SERVICE_MANAGEMENT_URL} = 'https://management.core.windows.net/'
#I did NOT set AZCONTAINERREGISTRY_CLOUD, had to reset that to avoid a panic
$env:AZURE_SUBSCRIPTION_ID=$env:AZCONTAINERREGISTRY_SUBSCRIPTION_ID
$env:PROXY_MANUAL_START="true"
$env:AZURE_RECORD_MODE="record"

If you need to make changes to the test framework, and also need to reference that updated local go code. You need to adjust the following.

C:/repo/azure-sdk-for-go [main]|>git diff sdk/containers/azcontainerregistry/go.mod
diff --git a/sdk/containers/azcontainerregistry/go.mod b/sdk/containers/azcontainerregistry/go.mod
index 132a7273c0..8c28f09f81 100644
--- a/sdk/containers/azcontainerregistry/go.mod
+++ b/sdk/containers/azcontainerregistry/go.mod
@@ -25,3 +25,5 @@ require (
        golang.org/x/text v0.14.0 // indirect
        gopkg.in/yaml.v3 v3.0.1 // indirect
 )
+
+replace github.com/Azure/azure-sdk-for-go/sdk/internal => ../../../sdk/internal

The addition of replace is what enables this. Then in recording.go, change the defaultOptions proxyPort to 5001. That way you can get a connection to the proxy port.

C

This language doesn't utilize the proxy. No instructions.

CPP

JS

  1. PROXY_MANUAL_START=true
  2. rush update
  3. cd <target package>
  4. rush build -t .
  5. rushx test:node

Java

  1. Install maven. Ensure it's available on the path.
  2. Set TF_BUILD or CI to true so that the java tests look for an already running proxy.
  3. Install necessary prereqs for the package being tested
    • mvn install -f sdk/core/azure-core/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" -DskipTestCompile "-Dcheckstyle.skip=true"
    • mvn install -f sdk/core/azure-core-test/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
    • mvn install -f common/perf-test-core/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
    • mvn clean install -f sdk/parents/azure-perf-test-parent/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
    • mvn install -f sdk/core/azure-core-perf/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
    • mvn install -f sdk/resourcemanager/ "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
  4. mvn surefire:test -f sdk/resourcemanager/azure-resourcemanager-compute/pom.xml -Dtest=TestProxyTests#testRecordWithRedaction
    • -Dtest=<testClassName>#<testFunctionName>

Samples

mvn install -f sdk/containerregistry/azure-containers-containerregistry/pom.xml "-Dcodesnippet.skip" "-Drevapi.skip" "-Dspotbugs.skip" -DskipTests=true "-Djacoco.skip" "-Dmaven.javadoc.skip=true" "-Dcheckstyle.skip=true"
mvn surefire:test -f sdk/containerregistry/azure-containers-containerregistry/pom.xml -Dtest=ContainerRegistryContentClientIntegrationTests#canUploadDockerManifestWithTagAsync
mvn surefire:test -f sdk/containerregistry/azure-containers-containerregistry/pom.xml -Dtest=ContainerRegistryContentClientIntegrationTests#canUploadDockerManifestWithTag
mvn surefire:test -f sdk/containerregistry/azure-containers-containerregistry/pom.xml -Dtest=ContainerRegistryContentClientIntegrationTests#getOciListManifest
mvn surefire:test -f sdk/containerregistry/azure-containers-containerregistry/pom.xml -Dtest=ContainerRegistryContentClientIntegrationTests#getDockerManifestListType
mvn surefire:test -f sdk/containerregistry/azure-containers-containerregistry/pom.xml -Dtest=ContainerRegistryContentClientIntegrationTests#getOciListManifestAsync

Get a test-proxy release

url="https://github.com/Azure/azure-sdk-tools/releases/download/Azure.Sdk.Tools.TestProxy_1.0.0-dev.20240515.4/test-proxy-standalone-linux-x64.tar.gz"
directory="/path/to/destination/directory"
mkdir -p "$directory"
wget "$url" -O /tmp/test-proxy-standalone-linux-x64.tar.gz
tar -xzf /tmp/test-proxy-standalone-linux-x64.tar.gz -C "$directory"
rm /tmp/test-proxy-standalone-linux-x64.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment