Skip to content

Commit

Permalink
feat: add automation script to test backends
Browse files Browse the repository at this point in the history
  • Loading branch information
SirusCodes committed Jan 6, 2023
1 parent 277dad9 commit 16326c2
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 35 deletions.
18 changes: 9 additions & 9 deletions backends/dart_conduit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,63 +56,63 @@ packages:
name: conduit
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.5"
version: "3.2.12"
conduit_codable:
dependency: transitive
description:
name: conduit_codable
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_common:
dependency: transitive
description:
name: conduit_common
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_config:
dependency: transitive
description:
name: conduit_config
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_isolate_exec:
dependency: transitive
description:
name: conduit_isolate_exec
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_open_api:
dependency: transitive
description:
name: conduit_open_api
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_password_hash:
dependency: transitive
description:
name: conduit_password_hash
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_runtime:
dependency: transitive
description:
name: conduit_runtime
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
conduit_test:
dependency: "direct dev"
description:
name: conduit_test
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.4"
version: "3.2.11"
convert:
dependency: transitive
description:
Expand Down
10 changes: 10 additions & 0 deletions backends/dart_conduit/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

echo 'Getting dependencies...'
dart pub get

echo 'Activating conduit'
dart pub global activate conduit

echo 'Running conduit'
conduit serve -a 127.0.0.1 -p 8080
7 changes: 0 additions & 7 deletions backends/dart_conduit/setup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion backends/dart_frog_backend/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:

dependencies:
compute: ^1.0.2
dart_frog: ^0.2.0
dart_frog: ^0.3.1
shelf_multipart: ^1.0.0

dev_dependencies:
Expand Down
7 changes: 5 additions & 2 deletions backends/dart_frog_backend/setup.sh → backends/dart_frog_backend/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!bin/sh
#!/bin/sh

echo 'Getting dependencies...'
dart pub get
Expand All @@ -7,4 +7,7 @@ echo 'Activating dart_frog_cli'
dart pub global activate dart_frog_cli

echo 'Build server'
dart_frog_cli build
dart_frog build

echo 'Run server'
dart build/bin/server.dart
10 changes: 10 additions & 0 deletions backends/dart_minerva/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

echo 'Getting dependencies...'
dart pub get

echo 'Activating Minerva...'
dart pub global activate minerva

echo 'Running Minerva...'
minerva run
7 changes: 0 additions & 7 deletions backends/dart_minerva/setup.sh

This file was deleted.

7 changes: 7 additions & 0 deletions backends/dart_shelf/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

echo 'Getting dependencies...'
dart pub get

echo 'Running server...'
dart bin/server.dart
4 changes: 0 additions & 4 deletions backends/dart_shelf/setup.sh

This file was deleted.

7 changes: 7 additions & 0 deletions backends/node_express/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

echo 'Getting dependencies...'
npm install

echo 'Running server...'
npm start
4 changes: 0 additions & 4 deletions backends/node_express/setup.sh

This file was deleted.

5 changes: 4 additions & 1 deletion backends/py_flask/setup.sh → backends/py_flask/run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!bin/sh
#!/bin/sh

echo 'Getting dependencies...'
pip install -r requirements.txt

echo 'Running server...'
python serve.py
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@

# Conventional directory for build output.
build/
results/
25 changes: 25 additions & 0 deletions benchmark/bin/benchmark.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:convert';
import 'dart:io';

import 'package:benchmark/benchmark.dart' as benchmark;

const interation = 20;

Future<int> main(List<String> arguments) async {
final name = arguments.length == 1 ? arguments[0] : "none";

final List<double> rttGet = [],
rttPost = [],
rttGetParallel = [],
Expand Down Expand Up @@ -50,5 +53,27 @@ Future<int> main(List<String> arguments) async {
print("\nJSON parsing speed");
print("Parse JSON: ${parseJsonTime.average()}ms");

saveResults(
{
"get_rtt": rttGet.average(),
"post_rtt": rttPost.average(),
"get_rtt_parallel": rttGetParallel.average(),
"post_rtt_parallel": rttPostParallel.average(),
"send_file": sendFileTime.average(),
"parse_json": parseJsonTime.average(),
"file_size": fileSize,
},
name,
);

return 0;
}

void saveResults(Map<String, num> result, String name) {
final file = File("./results/$name.json");
if (file.existsSync()) {
file.deleteSync();
}
file.createSync(recursive: true);
file.writeAsStringSync(jsonEncode(result));
}
81 changes: 81 additions & 0 deletions generate-report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh

set -eu;

# Set up dart pub environment
export PATH="$PATH":"$HOME/.pub-cache/bin";

(
cd "benchmark";
dart pub get;
)

cd "$(dirname "$0")";

TEST_BACKENDS=$(ls backends);
if [ "$#" -gt 0 ]; then
TEST_BACKENDS="$*";
fi

for backend in ${TEST_BACKENDS}; do
if [ "${backend}" = "dart_conduit" ]; then
echo "skipping ${backend} due to issues";
continue;
fi

echo "testing ${backend}";

(
cd "backends/${backend}";
chmod +x ./run.sh;
./run.sh;
) | sed "s/^/ /" &

# wait for server to start
while ! curl -q "http://127.0.0.1:8080" > /dev/null 2>&1; do
sleep 3;
done

# run tests
echo "running tests - ${backend}";
(
cd "benchmark";
dart run benchmark ${backend};
)

# kill children processes
echo "killing ${backend} process";
children_pids="";
for pid in /proc/*; do
case "${pid}" in
/proc/*[!0-9]* | "/proc/$$")
continue;
;;
*)
if grep -P "^\d+ \(.*\) [RSDZTW] \d+ $$ " "${pid}/stat" > /dev/null; then
children_pids="${children_pids} ${pid#/proc/}";
fi
;;
esac
done

children_running="true";
while [ "${children_running}" = "true" ]; do
children_running="false";
for pid in ${children_pids}; do
if ps -p "${pid}" > /dev/null; then
children_running="true";
echo "killing ${backend} with pid ${pid}";
kill "${pid}";
fi
done

sleep 1;
done

# wait for server to stop
# while curl -q "http://127.0.0.1:8080" > /dev/null 2>&1; do
# sleep 3;
# done
echo;
done

0 comments on commit 16326c2

Please sign in to comment.