Skip to content

Commit 2387074

Browse files
Add tests for pythoin
1 parent e16f26e commit 2387074

File tree

8 files changed

+95
-79
lines changed

8 files changed

+95
-79
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/local.settings.json

functions-int-tests/src/test/java/com/microsoft/azure/kusto/functions/FunctionsMultiLangTests.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class FunctionsMultiLangTests extends Simulation {
4545
// File name in docker compose file
4646
private static final String BASE_IMAGE = "baseimage";
4747

48-
private static final int HOST_PORT = Integer.getInteger("port", 7103);
48+
private static final int HOST_PORT = Integer.getInteger("port", 7071);
4949
private static final Boolean HOLD_CONTAINER = Boolean.getBoolean("debug");
5050
private static final Boolean RUN_TRIGGER = Boolean.getBoolean("runTrigger");
5151
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
@@ -56,11 +56,6 @@ public class FunctionsMultiLangTests extends Simulation {
5656

5757
private DockerComposeContainer<?> environment;
5858

59-
private final Map<String, Integer> languagePortMap = Stream
60-
.of(new String[][] { { "outofproc", "7101" }, { "java", "7102" }, { "node", "7103" }, { "python", "7104" },
61-
{ "csharp", "7105" } })
62-
.collect(Collectors.collectingAndThen(Collectors.toMap(data -> data[0], data -> Integer.parseInt(data[1])),
63-
Collections::<String, Integer> unmodifiableMap));
6459
private String language = getProperty("language", "node");
6560

6661
public FunctionsMultiLangTests() throws JsonProcessingException {
@@ -75,13 +70,7 @@ public void before() {
7570
// Copy the project into the container
7671
// Replace the DLL file
7772
language = getProperty("language", "node");
78-
if (!languagePortMap.containsKey(language)) {
79-
logger.warn(
80-
"Language " + language + " is not in the list of accepted languages for test. Accepted languages - "
81-
+ languagePortMap.keySet());
82-
System.exit(137);
83-
}
84-
int hostPort = languagePortMap.get(language);
73+
int hostPort = 7071;
8574
String dockerComposeFile = RUN_TRIGGER ? PATH_TO_DOCKER_COMPOSE : PATH_TO_DOCKER_COMPOSE_WITH_NO_RMQ;
8675
File absoluteFilePath = new File(dockerComposeFile).getAbsoluteFile();
8776
try {
@@ -189,9 +178,9 @@ public void after() {
189178
"/src/samples-%s/target/azure-functions/kustojavafunctionssample-20230130111810292/func-logs.txt",
190179
language);
191180
} else if ("outofproc".equalsIgnoreCase(language)) {
192-
containerPath = String.format("/src/samples-%s/bin/Debug/net6/func-logs.txt", language);
181+
containerPath = String.format("/src/samples-%s/bin/Debug/net8.0/publish/func-logs.txt", language);
193182
} else if ("csharp".equalsIgnoreCase(language)) {
194-
containerPath = String.format("/src/samples-%s/bin/Debug/net6/func-logs.txt", language);
183+
containerPath = String.format("/src/samples-%s/bin/Debug/net8.0/func-logs.txt", language);
195184
} else {
196185
containerPath = String.format("/src/samples-%s/func-logs.txt", language);
197186
}

samples/docker/Docker-template.dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y python3.11 pyth
4444
RUN python3.11 -m venv /opt/venv
4545
ENV PATH="/opt/venv/bin:$PATH"
4646
#Python installation complete
47+
RUN apt-get update && apt-get install --no-install-recommends -y dotnet-sdk-8.0 && \
48+
apt-get clean && rm -rf /var/lib/apt/lists/*
49+
#.NET 8 SDK for dotnet-isolated functions
4750
COPY ./samples/docker/host.json /src/host.json
4851
# Copy the DLL to the target use this for the tests
4952
COPY ./src/bin/Release/netstandard2.1/Microsoft.Azure.WebJobs.Extensions.Kusto.dll /src/Microsoft.Azure.WebJobs.Extensions.Kusto.dll

samples/docker/docker-compose-no-rmq.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
version: '3'
21
services:
32
baseimage:
43
image: func-az-kusto-base:latest
54
hostname: func-az-kusto-base
65
ports:
7-
- "7101:7101"
8-
- "7102:7102"
9-
- "7103:7103"
10-
- "7104:7104"
11-
- "7105:7105"
6+
- "7071:7071"
127
azurite:
138
image: mcr.microsoft.com/azure-storage/azurite
149
hostname: azurite

samples/docker/docker-compose.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
version: '3'
21
services:
32
baseimage:
43
image: func-az-kusto-base:latest
54
hostname: func-az-kusto-base
65
ports:
7-
- "7101:7101"
8-
- "7102:7102"
9-
- "7103:7103"
10-
- "7104:7104"
11-
- "7105:7105"
6+
- "7071:7071"
127
rabbitmq:
138
image: rabbitmq:3.11.9-management
149
hostname: rabbitmq

samples/docker/start-functions.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ cd "$SAMPLES_DIR"
2828
case "$language" in
2929
outofproc)
3030
echo "Starting out-of-process dotnet-isolated worker"
31-
cd bin/Debug/net8.0
32-
func start --dotnet-isolated --verbose --port "$port" >> func-logs.txt &
31+
cd bin/Debug/net8.0/publish
32+
FUNCTIONS_WORKER_RUNTIME=dotnet-isolated func start --dotnet-isolated --no-build --verbose --port "$port" >> func-logs.txt &
3333
;;
3434
csharp)
3535
echo "Starting C# in-process worker"
3636
cd bin/Debug/net8.0
37-
func start --csharp --verbose --port "$port" >> func-logs.txt &
37+
FUNCTIONS_WORKER_RUNTIME=dotnet func start --csharp --verbose --port "$port" >> func-logs.txt &
3838
;;
3939
node)
4040
echo "Starting Node.js (JavaScript) worker"
41-
func start --javascript --verbose --port "$port" >> func-logs.txt &
41+
FUNCTIONS_WORKER_RUNTIME=node func start --javascript --verbose --port "$port" >> func-logs.txt &
4242
;;
4343
java)
4444
echo "Starting Java worker"
4545
cd target/azure-functions/kustojavafunctionssample-20230130111810292
46-
func start --java --verbose --port "$port" >> func-logs.txt &
46+
FUNCTIONS_WORKER_RUNTIME=java func start --java --verbose --port "$port" >> func-logs.txt &
4747
;;
4848
python)
4949
echo "Starting Python worker"
50-
func start --python --verbose --port "$port" >> func-logs.txt &
50+
FUNCTIONS_WORKER_RUNTIME=python PYTHONPATH="$SAMPLES_DIR" func start --python --verbose --port "$port" >> func-logs.txt &
5151
;;
5252
powershell)
5353
echo "Starting PowerShell worker"
54-
func start --powershell --verbose --port "$port" >> func-logs.txt &
54+
FUNCTIONS_WORKER_RUNTIME=powershell func start --powershell --verbose --port "$port" >> func-logs.txt &
5555
;;
5656
*)
5757
echo "Error: Unsupported language '$language'"

samples/samples-python/Common/__init__.py

Whitespace-only changes.

scripts/run-functional-tests-e2e.sh

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@
22
set -euo pipefail
33

44
# Wrapper script to build the E2E test Docker image and configure local settings.
5-
# Usage: ./run-functional-tests-e2e.sh [KustoConnectionString]
6-
# KustoConnectionString is built from CLUSTER and DATABASE env vars if set,
7-
# otherwise falls back to the first positional parameter.
5+
# Usage: ./run-functional-tests-e2e.sh <Cluster> <Database> [Language]
6+
#
7+
# Cluster and Database can also be set via CLUSTER and DATABASE env vars.
8+
# Language selects which sample to test (must be a LANG_MAP key, e.g.
9+
# samples-csharp, samples-java, etc.). Can also be set via SAMPLE_LANG env var.
10+
# Defaults to samples-node.
811

912
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1013
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
1114
cd "$REPO_ROOT"
1215

13-
# Build KustoConnectionString from CLUSTER/DATABASE env vars, or fall back to $1
14-
if [ -n "${CLUSTER:-}" ] && [ -n "${DATABASE:-}" ]; then
15-
KUSTO_CONNECTION_STRING="Data Source=${CLUSTER};Database=${DATABASE};Fed=True"
16-
echo "==> Using KustoConnectionString from CLUSTER and DATABASE env vars"
17-
elif [ $# -ge 1 ]; then
18-
KUSTO_CONNECTION_STRING="$1"
19-
echo "==> Using KustoConnectionString from parameter"
16+
# Build KustoConnectionString from positional args or CLUSTER/DATABASE env vars.
17+
# Positional args take precedence over env vars.
18+
LANG_ARG=""
19+
if [ $# -ge 2 ]; then
20+
CLUSTER="$1"
21+
DATABASE="$2"
22+
LANG_ARG="${3:-}"
23+
echo "==> Using Cluster and Database from positional parameters"
24+
elif [ -n "${CLUSTER:-}" ] && [ -n "${DATABASE:-}" ]; then
25+
LANG_ARG="${1:-}"
26+
echo "==> Using Cluster and Database from env vars"
2027
else
21-
echo "Error: Either set CLUSTER and DATABASE env vars, or pass KustoConnectionString as \$1"
22-
echo "Usage: $0 [KustoConnectionString]"
23-
echo " CLUSTER - Kusto cluster URL (e.g. https://mycluster.kusto.windows.net)"
24-
echo " DATABASE - Kusto database name"
28+
echo "Error: Provide Cluster and Database as positional args, or set CLUSTER and DATABASE env vars"
29+
echo "Usage: $0 <Cluster> <Database> [Language]"
30+
echo " Cluster - Kusto cluster URL (e.g. https://mycluster.kusto.windows.net)"
31+
echo " Database - Kusto database name"
32+
echo " Language - LANG_MAP key (e.g. samples-csharp, samples-java). Default: samples-node"
2533
exit 1
2634
fi
2735

36+
KUSTO_CONNECTION_STRING="Data Source=${CLUSTER};Database=${DATABASE};Fed=True"
37+
2838
# Source access token from az CLI if not already set
2939
if [ -z "${ACCESS_TOKEN:-}" ]; then
3040
echo "==> Fetching access token from az CLI..."
@@ -33,48 +43,71 @@ fi
3343

3444
# Map sample directories to their FUNCTIONS_WORKER_RUNTIME values
3545
declare -A LANG_MAP=(
36-
["samples-csharp"]="dotnet"
46+
["samples-csharp"]="csharp"
3747
["samples-java"]="java"
3848
["samples-node"]="node"
3949
["samples-outofproc"]="dotnet-isolated"
4050
["samples-powershell"]="powershell"
4151
["samples-python"]="python"
4252
)
4353

54+
FUNC_PORT=7071
55+
56+
# Resolve language: positional arg > SAMPLE_LANG env var > default (samples-node)
57+
if [ -n "$LANG_ARG" ]; then
58+
SAMPLE_LANG="$LANG_ARG"
59+
else
60+
SAMPLE_LANG="${SAMPLE_LANG:-samples-node}"
61+
fi
62+
63+
# Validate SAMPLE_LANG against LANG_MAP
64+
if [ -z "${LANG_MAP[$SAMPLE_LANG]+_}" ]; then
65+
echo "Error: '${SAMPLE_LANG}' is not a valid language key."
66+
echo "Valid keys: ${!LANG_MAP[*]}"
67+
exit 1
68+
fi
69+
echo "==> Running tests for language: ${SAMPLE_LANG} (runtime: ${LANG_MAP[$SAMPLE_LANG]})"
70+
71+
runtime="${LANG_MAP[$SAMPLE_LANG]}"
72+
4473
echo "=== Step 1: Building Docker image ==="
4574
"$SCRIPT_DIR/build-docker-image.sh"
4675

47-
echo "=== Step 2: Generating local.settings.json for each language sample ==="
76+
echo "=== Step 2: Generating local.settings.json for ${SAMPLE_LANG} ==="
4877

4978
CONN_STRING_WITH_TOKEN="${KUSTO_CONNECTION_STRING};AAD Federated Security=True;UserToken=${ACCESS_TOKEN}"
5079

51-
for sample_dir in "${!LANG_MAP[@]}"; do
52-
runtime="${LANG_MAP[$sample_dir]}"
53-
target_dir="samples/${sample_dir}"
54-
target="${target_dir}/local.settings.json"
55-
56-
if [ ! -d "$target_dir" ]; then
57-
echo "Warning: ${target_dir} does not exist, skipping"
58-
continue
59-
fi
60-
61-
echo "Creating ${target} with FUNCTIONS_WORKER_RUNTIME=${runtime}"
62-
63-
# Use jq if available for safe JSON manipulation, otherwise fall back to sed
64-
if command -v jq &>/dev/null; then
65-
jq \
66-
--arg runtime "$runtime" \
67-
--arg connStr "$CONN_STRING_WITH_TOKEN" \
68-
'.Values.FUNCTIONS_WORKER_RUNTIME = $runtime | .Values.KustoConnectionString = $connStr' \
69-
local.settings.json.example > "${target}"
70-
else
71-
sed \
72-
-e "s/<lang>/${runtime}/" \
73-
-e "s|<KustoConnectionString>|${CONN_STRING_WITH_TOKEN//|/\\|}|" \
74-
local.settings.json.example > "${target}"
75-
fi
76-
done
77-
78-
echo "=== Step 3: Running functional tests ==="
80+
target_dir="samples/${SAMPLE_LANG}"
81+
target="${target_dir}/local.settings.json"
82+
83+
if [ ! -d "$target_dir" ]; then
84+
echo "Error: ${target_dir} does not exist"
85+
exit 1
86+
fi
87+
88+
rm -f "${target}"
89+
echo "Creating ${target} with FUNCTIONS_WORKER_RUNTIME=${runtime}"
90+
91+
if command -v jq &>/dev/null; then
92+
jq \
93+
--arg runtime "$runtime" \
94+
--arg connStr "$CONN_STRING_WITH_TOKEN" \
95+
'.Values.FUNCTIONS_WORKER_RUNTIME = $runtime | .Values.KustoConnectionString = $connStr' \
96+
local.settings.json.example > "${target}"
97+
else
98+
sed \
99+
-e "s/<lang>/${runtime}/" \
100+
-e "s|<KustoConnectionString>|${CONN_STRING_WITH_TOKEN//|/\\|}|" \
101+
local.settings.json.example > "${target}"
102+
fi
103+
104+
if [ "$SAMPLE_LANG" = "samples-outofproc" ]; then
105+
echo "=== Step 3: Building ${SAMPLE_LANG} ==="
106+
dotnet publish "${target_dir}" -c Debug -o "${target_dir}/bin/Debug/net8.0/publish"
107+
cp "${target}" "${target_dir}/bin/Debug/net8.0/publish/local.settings.json"
108+
fi
109+
110+
echo "=== Step 4: Running functional tests ==="
79111
cd "$REPO_ROOT/functions-int-tests"
80-
mvn clean gatling:test
112+
test_language="${SAMPLE_LANG#samples-}"
113+
mvn clean gatling:test -Dlanguage="${test_language}" -Dport="${FUNC_PORT}"

0 commit comments

Comments
 (0)