Skip to content

Commit

Permalink
adds docs from avaliability tests to the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
JTrenerry committed Jun 2, 2024
1 parent c38f0a6 commit 62c375a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/AVALIABILITY_TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# UniBasement-Avaliability-Tests
Seperate Repo to keep my pi nice and smol :)

## Overview
A cron job was setup on a raspberry pi to run `script/script.sh` every 5 minutes.

The k6 test:
* sends a `GET` request to the UniBasement frontend homepage to verify the user facing site is accessible
* sends a `GET` request to the UniBasement backend courses route and checks the response body to verify the backend and database are both running


## Results
The test was running for 2 days, with only a 15 minute downtime at midnight on the 28th May. This means the uptime was 99.5%, which exceeds the required 99% uptime in the proposal.
3 changes: 3 additions & 0 deletions tests/avaliability_tests/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

k6 run ./test.js | grep -Poz '(?s)(?<=---).*?(?=---)' >> log.txt
29 changes: 29 additions & 0 deletions tests/avaliability_tests/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { check, sleep } from "k6";
import http from "k6/http";

export const options = {
duration: '10s'
};

const frontendUrl = 'http://unibasement.g6.csse6400.xyz/'
const backendUrl = 'http://unibasementBackend-2061383905.us-east-1.elb.amazonaws.com:8080/api/'

export default function () {
let res = http.get(frontendUrl);
check(res, {
"frontend status was 200": (r) => r.status === 200,
});

res = http.get(backendUrl + 'courses');
check(res, {
"backend status was 200": (r) => r.status === 200,
"backend body contains list of courses": (r) => r.json().length > 0 && !!r.json()[0].courseCode,
});

sleep(0.1);
}

export function handleSummary(output) {
const formatted = output.root_group.checks.map((c) => `'${c.name}': ${c.passes}/${c.passes + c.fails}`)
return { stdout: `---\n[${new Date()}]\n` + formatted.join('\n') + '\n---\n' }
}

0 comments on commit 62c375a

Please sign in to comment.