Skip to content

Commit 372b71f

Browse files
Add debugging tests section (#541)
1 parent 55603f9 commit 372b71f

File tree

8 files changed

+62
-11
lines changed

8 files changed

+62
-11
lines changed

.vscode/launch.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"request": "attach",
1414
"port": 9229,
1515
"preLaunchTask": "func: host start"
16+
},
17+
{
18+
"name": "Attach to Function Host",
19+
"type": "coreclr",
20+
"request": "attach",
21+
"processName": "func.exe"
1622
}
1723
]
1824
}

samples/samples-java/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"options": {
1010
"cwd": "${workspaceFolder}/target/azure-functions/samples-java-1665766173929"
1111
},
12-
"dependsOn": "package (functions)"
12+
"dependsOn": "package (functions)",
13+
"label": "func: host start"
1314
},
1415
{
1516
"label": "package (functions)",

samples/samples-js/.vscode/tasks.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
2-
"version": "2.0.0",
3-
"tasks": [
2+
"version": "2.0.0",
3+
"tasks": [
44
{
55
"type": "func",
66
"command": "host start",
77
"problemMatcher": "$func-node-watch",
88
"isBackground": true,
9-
"dependsOn": "npm install (functions)"
9+
"dependsOn": "npm install (functions)",
10+
"label": "func: host start"
1011
},
1112
{
1213
"type": "shell",
1314
"label": "npm install (functions)",
14-
"command": "npm install"
15+
"command": "npm install",
1516
},
1617
{
1718
"type": "shell",

samples/samples-outofproc/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
},
6464
"command": "host start",
6565
"isBackground": true,
66-
"problemMatcher": "$func-dotnet-watch"
66+
"problemMatcher": "$func-dotnet-watch",
67+
"label": "func: host start"
6768
}
6869
]
6970
}

samples/samples-powershell/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"type": "func",
66
"command": "host start",
77
"problemMatcher": "$func-powershell-watch",
8-
"isBackground": true
8+
"isBackground": true,
9+
"label": "func: host start"
910
}
1011
]
1112
}

samples/samples-python/.vscode/tasks.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
2-
"version": "2.0.0",
3-
"tasks": [
2+
"version": "2.0.0",
3+
"tasks": [
44
{
55
"type": "func",
66
"command": "host start",
77
"problemMatcher": "$func-python-watch",
88
"isBackground": true,
99
"dependsOn": "pip install (functions)",
10+
"label": "func: host start"
1011
},
1112
{
1213
"label": "pip install (functions)",

test/Integration/test-java/.vscode/tasks.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"options": {
1010
"cwd": "${workspaceFolder}/target/azure-functions/test-java-1666041146813"
1111
},
12-
"dependsOn": "package (functions)"
12+
"dependsOn": "package (functions)",
13+
"label": "func: host start"
1314
},
1415
{
1516
"label": "package (functions)",

test/README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,49 @@ Our integration tests are based on functions from the samples project. To run in
9494
}
9595
```
9696
97-
## Troubleshooting Tests
97+
## Troubleshooting Test Failures
9898
9999
This section lists some things to try to help troubleshoot test failures
100100
101+
### Debug Integration tests
102+
103+
You can debug tests locally by following these steps.
104+
105+
The first part is to identify what you want to debug so you know which process to attach to. There are between 2 and 3 different processes to attach to :
106+
107+
#### Test Runner
108+
109+
To debug the test code itself (anything under the `test` folder) you will need to attach to the VS Test Runner that's running the tests.
110+
111+
Visual Studio : Right click on the test in the test explorer and click "Debug"
112+
Visual Studio Code : Install a test explorer extension such as [.NET Core Test Explorer](https://marketplace.visualstudio.com/items?itemName=formulahendry.dotnet-test-explorer), go to the Tests panel, find the `.NET Test Explorer` view, right click the test you want to run and click "Debug Test"
113+
114+
#### Function Host
115+
116+
To debug either any core extension code (anything under the `src` folder) OR function code for .NET In-Process tests you will need to attach to the Function Host that's running the functions.
117+
118+
To do this and be able to set breakpoints before the test runs you will need to follow these steps :
119+
120+
1. Go to [IntegrationTestBase.cs](./Integration/IntegrationTestBase.cs) and in `StartFunctionHost` add a `return;` on the first line - this is to skip having the test start up the function host itself (since you'll be doing it manually)
121+
2. `cd` to the directory containing the functions to run - this will be in the `test/bin/Debug/net6/SqlExtensionSamples/<LANG>` folder (e.g. `test/bin/Debug/net6/SqlExtensionSamples/samples-csharp`)
122+
3. Run `func host start --functions <FUNCTION_NAME>` - replacing `<FUNCTION_NAME>` with the name of the function you want to debug (e.g. `func host start --functions AddProduct`)
123+
4. Attach to the func.exe process
124+
* Visual Studio : Use `Attach to Process...`.
125+
* VS Code you can use `Attach to Function Host` debug target (at the root level of the project)
126+
127+
**NOTE** If you don't see your breakpoints appear make sure you're using the correct version of the extension DLL. For non-.NET languages this will mean copying over the latest locally built version to the extension bundle as detailed [here](#extension-bundle). If you don't do this the host will be using a different version of the DLL that you won't have symbols for so breakpoints won't be able to load.
128+
5. Run your test
129+
130+
#### Function Worker (Non .NET Isolated Functions only)
131+
132+
For all functions that run in a worker process (which is everything other than .NET In-Process functions) if you need to debug the function code itself then you will need to use the native debugger to attach to the process. The easiest way to do that is to follow these steps:
133+
134+
1. Open up a new instance of VS Code into the samples/test folder containing the function you want to debug (e.g. `samples/samples-powershell` or `test/Integration/test-powershell`)
135+
2. Modify the `.vscode/tasks.json` file for that folder and add `--functions <FUNCTION_NAME>` to the end of the command property for `func: host start`. (e.g. `"command": "host start --functions AddProduct"`)
136+
3. Update the `local.settings.json` in that folder and fill in the value for `SqlConnectionString` (since the test is no longer controlling the startup of the function host)
137+
4. Click F5 to run the `Attach to <LANG> Functions` target, this will launch the specified function and attach the debugger to it
138+
5. Run your test
139+
101140
### Enable debug logging on the Function
102141
103142
Enabling debug logging can greatly increase the information available which can help track down issues or understand at least where the problem may be. To enable debug logging for the Function open [host.json](../samples/samples-csharp/host.json) and add the following property to the `logLevel` section, then rebuild and re-run your test.

0 commit comments

Comments
 (0)