Skip to content

Commit

Permalink
JS implementation of basic perf testing app (#5494)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyashton authored Aug 1, 2023
1 parent 3ea079c commit a6fdd26
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,14 @@ if(BUILD_TESTS)
100000
)

add_perf_test(
NAME pi_basic_js
PYTHON_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/tests/infra/basicperf.py
CLIENT_BIN ./submit
ADDITIONAL_ARGS --js-app-bundle ${CMAKE_SOURCE_DIR}/samples/apps/basic/js
--repetitions 100000
)

if(WORKER_THREADS)
add_perf_test(
NAME pi_basic_mt
Expand Down
22 changes: 22 additions & 0 deletions samples/apps/basic/js/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"endpoints": {
"/records/{key}": {
"get": {
"js_module": "basic.js",
"js_function": "get_record",
"forwarding_required": "sometimes",
"authn_policies": ["user_cert"],
"mode": "readonly",
"openapi": {}
},
"put": {
"js_module": "basic.js",
"js_function": "put_record",
"forwarding_required": "always",
"authn_policies": ["user_cert"],
"mode": "readwrite",
"openapi": {}
}
}
}
}
34 changes: 34 additions & 0 deletions samples/apps/basic/js/src/basic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
let records_table = ccf.kv["records"];

export function put_record(request) {
const key = request.params.key;
if (key === undefined) {
return { statusCode: 404, body: "Missing key" };
}

records_table.set(ccf.strToBuf(key), request.body.arrayBuffer());

return {
statusCode: 204,
};
}

export function get_record(request) {
const key = request.params.key;
if (key === undefined) {
return { statusCode: 404, body: "Missing key" };
}

const val = records_table.get(ccf.strToBuf(key));
if (val === undefined) {
return { statusCode: 404, body: "No such key" };
}

return {
statusCode: 200,
headers: {
"content-type": "text/plain",
},
body: val,
};
}

0 comments on commit a6fdd26

Please sign in to comment.