Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TRIPS tenants in e2e test runs #23382

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"eslint": "~8.55.0",
"jest": "^29.6.2",
"mocha": "^10.2.0",
"node-fetch": "^2.6.9",
"prettier": "~3.0.3",
"pretty-quick": "^4.0.0",
"puppeteer": "^23.6.0",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions tools/pipelines/templates/get-trips-tenants-ci.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation and contributors. All rights reserved.
// Licensed under the MIT License.

import fetch from "node-fetch";

async function main() {
const requestBody = {
"Resources": [
{
"name": "tenant1", // A user-assigned identifier for the specific resource
"profileName": "FluidFrameworkTenantPool", // The type of the resource (i.e. pool name)
},
],
"ModuleName": "FFTestModule", // Metadata used for tracking the source of the request (can be anything)
"Count": 1, // How many copies of the above resources to allocate for the reservation. Should almost always be 1
};

const bearerToken = await fetch(
"https://tdff5prd.office.net/v2.0/reservations/current?isSynthetic=false&durationMinutes=75",
{
method: "POST",
body: JSON.stringify(requestBody),
},
).then((response) => response.json());

const stringBearerToken = JSON.stringify(bearerToken);

// step 2: wait for resource hydration
// returns "Ready" or "Not Ready"
const status = await fetch("https://tdff5prd.office.net/v2.0/reservations/current/status", {
method: "GET",
headers: {
// are single quotes needed here in addition to backticks?
Authorization: `'BEARER ${stringBearerToken}'`,
},
}).then((response) => response.text());
console.log(`status: ${status}`);
const stringStatus = JSON.stringify(status);
console.log(`string status: ${stringStatus}`);

// step 3: check out hydrated resource
const credentials = await fetch(
"https://tdff5prd.office.net/v2.0/reservations/current/modules?moduleName=FFTestModule",
{
method: "GET",
headers: {
Authorization: `BEARER ${stringBearerToken}`,
// don't think this is right
"TDF-ReservationClient": "odspTests",
},
},
).then((response) => response.json());
const loginTenants = JSON.stringify(credentials);
console.log(`##vso[task.setvariable variable=tenantCreds;issecret=true]${loginTenants}`);
console.log(`##vso[task.setvariable variable=stringBearerToken;]${stringBearerToken}`);
}

main().then(() => console.log("done"));
45 changes: 44 additions & 1 deletion tools/pipelines/templates/include-test-real-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,27 @@ stages:
key: '"compat-version-installs" | "$(Agent.OS)" | "${{ parameters.testCommand }}" | "${{ variant.name }}"'
path: ${{ parameters.testWorkspace }}/node_modules/@fluid-private/test-version-utils/node_modules/.legacy/

# Retrieve a tenant from the TRIPS tenant pool
# need to have some automated consent for the local flow
- task: AzureCLI@2
displayName: 'Set up and retrieve tenant credentials'
inputs:
azureSubscription: 'Fluid Framework Tests'
addSpnToEnvironment: true
scriptType: 'bash'
scriptLocation: 'inlineScript'
scriptPath: |
set -eu -o pipefail

az login --service-principal -u $servicePrincipalId -p $idToken --tenant $tenantId
node 'tools/pipelines/templates/get-trips-tenants-ci.mjs';

# run the test
- task: Npm@1
displayName: '[test] ${{ parameters.testCommand }} ${{ variant.flags }}'
continueOnError: ${{ parameters.continueOnError }}
env:
${{ parameters.env }}
login__odsp__test__tenants: $(tenantCreds)
inputs:
command: 'custom'
workingDir: ${{ parameters.testWorkspace }}/node_modules/${{ parameters.testPackage }}
Expand Down Expand Up @@ -439,6 +454,34 @@ stages:
condition: always()
continueOnError: true # Keep running subsequent tasks even if this one fails (e.g. the tinylicious log wasn't there)

# Release the tenant back to the TRIPS tenant pool
- task: AzureCLI@2
displayName: 'Cleanup resources'
inputs:
azureSubscription: 'Fluid Framework Tests'
addSpnToEnvironment: true
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
// define variables
moduleName="FFTestModule";

set -eu -o pipefail
az login --service-principal -u $servicePrincipalId -p $idToken --tenant $tenantId

node -e "
const fetch = require('fetch');

fetch("https://tdff5prd.office.net/v2.0/reservations/current/modules?moduleName=${moduleName}", {
method: "DELETE",
headers: {
// not sure if this access is correct
Authorization: `BEARER $(stringBearerToken)`,
// don't think this is right
"TDF-ReservationClient": "odspTests",
}).then((response) => response.json());
"

# Log Test Failures
# - template: include-process-test-results.yml
# parameters:
Expand Down
Loading