Skip to content

Commit

Permalink
added a basic performance test for v4 establishments and trusts
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestock-nimble committed Dec 19, 2023
1 parent 6eb7b38 commit 84b462c
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Dfe.Academies.Performance/scripts/get-establishment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
vus: 800,
duration: '30s',
// httpDebug: 'full',
};

const baseUrl = "https://localhost:5001/v4";

export default function () {
getEstablishmentsForTrust("UKPRN37cda865-dbe0-426f-9485-84c1cf3d8513");

getEstablishmentByUkPrn("UKPRN0b2ecaa7-4ec3-4138-805b-3d7d904962a4");

sleep(1);
}

function getEstablishmentsForTrust(ukprn) {
const res = http.get(`${baseUrl}/establishments/trust?trustUkPrn=${ukprn}`, {
headers: getHeaders()
});

isStatus200(res);
}

function getEstablishmentByUkPrn(ukprn) {
const res = http.get(`${baseUrl}/establishment/${ukprn}`, {
headers: getHeaders()
});

isStatus200(res);
}

function isStatus200(res) {
check(res, {
'status is 200': (r) => r.status === 200,
});
}

function getHeaders() {
return {
"ApiKey": "app-key",
"Content-Type": "application/json"
};
}
79 changes: 79 additions & 0 deletions Dfe.Academies.Performance/scripts/get-trust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
vus: 400,
duration: '30s',
// httpDebug: 'full',
};

const baseUrl = "https://localhost:5001/v4";

export default function () {

searchTrustByName("Name91b71279-6799-4f2c-843d-8e6b35ae7ffa");

getTrustByUkPrn("UKPRN692c06a7-089a-46be-ae3b-e4d6fee8126e");

searchTrustByUkPrn("UKPRN692c06a7-089a-46be-ae3b-e4d6fee8126e");

getTrustByCompaniesHouseNumber("CompaniesHouseNumbercfa7f419-f27e-4f6c-9266-9a9c560ae6a3");

getTrustByReferenceNumber("GroupID97be1318-42e1-4527-a75e-595ba4768153");

sleep(1);
}

function searchTrustByName(name) {
const res = http.get(`${baseUrl}/trusts?groupName=${name}&page=1&count=10`, {
headers: getHeaders()
});

isStatus200(res);
}

function searchTrustByUkPrn(ukprn) {
const res = http.get(`${baseUrl}/trusts?ukPrn=${ukprn}&page=1&count=10`, {
headers: getHeaders()
});

isStatus200(res);
}

function getTrustByUkPrn(ukprn) {
const res = http.get(`${baseUrl}/trust/${ukprn}`, {
headers: getHeaders()
});

isStatus200(res);
}

function getTrustByCompaniesHouseNumber(companiesHouseNumber) {
const res = http.get(`${baseUrl}/trust/companiesHouseNumber/${companiesHouseNumber}`, {
headers: getHeaders()
});

isStatus200(res);

}

function getTrustByReferenceNumber(trustReferenceNumber) {
const res = http.get(`${baseUrl}/trust/trustReferenceNumber/${trustReferenceNumber}`, {
headers: getHeaders()
});

isStatus200(res);
}

function isStatus200(res) {
check(res, {
'status is 200': (r) => r.status === 200,
});
}

function getHeaders() {
return {
"ApiKey": "app-key",
"Content-Type": "application/json"
};
}
95 changes: 95 additions & 0 deletions TramsDataApi.Test/Integration/V4/GenerateDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using Dfe.Academies.Academisation.Data;
using Dfe.Academies.Domain.Establishment;
using Dfe.Academies.Domain.Trust;
using System.Collections.Generic;
using System.Linq;
using TramsDataApi.Test.Fixtures;
using TramsDataApi.Test.Helpers;
using Xunit;

namespace TramsDataApi.Test.Integration.V4
{
[Collection(ApiTestCollection.ApiTestCollectionName)]
public class GenerateDataTests
{
private readonly ApiTestFixture _apiFixture;

public GenerateDataTests(ApiTestFixture fixture)
{
_apiFixture = fixture;
}

[Fact(Skip = "Generate data for performance testing on an adhoc basis")]
public void GenerateTrustData()
{
using var context = _apiFixture.GetMstrContext();
context.ChangeTracker.AutoDetectChangesEnabled = false;

for (var idx = 0; idx < 4000; idx++)
{
CreateDataSet(context);
}
}

private static TrustDataSet CreateDataSet(MstrContext context)
{
var trust = DatabaseModelBuilder.BuildTrust();
context.Add(trust);
context.SaveChanges();

var establishments = new List<EstablishmentDataSet>();

for (var idx = 0; idx < 3; idx++)
{
var establishment = DatabaseModelBuilder.BuildEstablishment();
var ifdPipeline = DatabaseModelBuilder.BuildIfdPipeline();
ifdPipeline.GeneralDetailsUrn = establishment.PK_GIAS_URN;

var establishmentDataSet = new EstablishmentDataSet()
{
Establishment = establishment,
IfdPipeline = ifdPipeline
};

context.Establishments.Add(establishment);
context.IfdPipelines.Add(ifdPipeline);

establishments.Add(establishmentDataSet);
}

context.SaveChanges();

var trustToEstablishmentLinks = LinkTrustToEstablishments(trust, establishments.Select(d => d.Establishment).ToList());

context.EducationEstablishmentTrusts.AddRange(trustToEstablishmentLinks);

context.SaveChanges();

var result = new TrustDataSet()
{
Trust = trust,
Establishments = establishments
};

return result;
}

private static List<EducationEstablishmentTrust> LinkTrustToEstablishments(Trust trust, List<Establishment> establishments)
{
var result = new List<EducationEstablishmentTrust>();

establishments.ForEach(establishment =>
{
var educationEstablishmentTrust = new EducationEstablishmentTrust()
{
TrustId = (int)trust.SK,
EducationEstablishmentId = (int)establishment.SK
};

result.Add(educationEstablishmentTrust);
});

return result;
}
}
}

0 comments on commit 84b462c

Please sign in to comment.