Skip to content
Merged
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
15 changes: 15 additions & 0 deletions examples/bench-plugin/bench-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@
function wp_codebox_bench_plugin_value(): int {
return 7;
}

add_action(
'rest_api_init',
static function (): void {
register_rest_route(
'wp-codebox-bench/v1',
'/value',
array(
'methods' => 'GET',
'callback' => static fn (): array => array( 'value' => wp_codebox_bench_plugin_value() ),
'permission_callback' => '__return_true',
)
);
}
);
6 changes: 5 additions & 1 deletion examples/bench-plugin/tests/bench/noop.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

return static function (): array {
$response = rest_do_request( new WP_REST_Request( 'GET', '/wp-codebox-bench/v1/value' ) );
$data = rest_get_server()->response_to_data( $response, false );

return array(
'metrics' => array(
'fixture_value' => wp_codebox_bench_plugin_value(),
'fixture_value' => wp_codebox_bench_plugin_value(),
'rest_route_visible' => isset( $data['value'] ) && 7 === (int) $data['value'] ? 1 : 0,
),
'metadata' => array(
'fixture' => 'bench-plugin',
Expand Down
8 changes: 8 additions & 0 deletions packages/runtime-playground/src/bench-command-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ foreach ($plugins_to_activate as $plugin_to_activate) {
throw new RuntimeException($activation->get_error_message());
}
}
if (!empty($plugins_to_activate)) {
do_action('plugins_loaded');
do_action('init');
}
if (did_action('rest_api_init')) {
$GLOBALS['wp_rest_server'] = null;
do_action('rest_api_init', rest_get_server());
}

function wp_codebox_bench_run_configured_workload(array $workload, string $plugin_path) {
$steps = isset($workload['run']) && is_array($workload['run']) ? $workload['run'] : array($workload);
Expand Down
1 change: 1 addition & 0 deletions scripts/recipe-bench-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ assert.equal(scenario.id, "noop")
assert.equal(scenario.file, "tests/bench/noop.php")
assert.equal(scenario.iterations, 2)
assert.equal(scenario.metrics.fixture_value_mean, 7)
assert.equal(scenario.metrics.rest_route_visible_mean, 1)
assert.equal(scenario.metadata.fixture, "bench-plugin")
const configured = output.benchResults.scenarios[1]
assert.equal(configured.id, "configured-env")
Expand Down