Skip to content

Commit

Permalink
fix(sb_core): add an API for chaos testing (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyannyacha authored Sep 25, 2024
1 parent 2b1945c commit 1c19701
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/sb_core/js/main_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Object.defineProperty(globalThis, 'EdgeRuntime', {
getRuntimeMetrics: () => /* async */ ops.op_runtime_metrics(),
applySupabaseTag: (src, dest) => applySupabaseTag(src, dest),
systemMemoryInfo: () => ops.op_system_memory_info(),
raiseSegfault: () => ops.op_raise_segfault(),
};
},
configurable: true,
Expand Down
11 changes: 10 additions & 1 deletion crates/sb_core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ fn op_set_raw(
Ok(())
}

#[op2(fast)]
fn op_raise_segfault(_state: &mut OpState) {
unsafe {
let ptr: *const i32 = std::ptr::null();
println!("{}", *ptr);
}
}

#[op2]
#[serde]
pub fn op_bootstrap_unstable_args(_state: &mut OpState) -> Vec<String> {
Expand All @@ -361,7 +369,8 @@ deno_core::extension!(
op_schedule_mem_check,
op_runtime_memory_usage,
op_set_raw,
op_bootstrap_unstable_args
op_bootstrap_unstable_args,
op_raise_segfault,
],
esm_entry_point = "ext:sb_core_main_js/js/bootstrap.js",
esm = [
Expand Down
11 changes: 11 additions & 0 deletions examples/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ Deno.serve(async (req: Request) => {
);
}

// if (pathname === '/_internal/segfault') {
// EdgeRuntime.raiseSegfault();
// return new Response(
// JSON.stringify({ 'message': 'ok' }),
// {
// status: STATUS_CODE.OK,
// headers,
// },
// );
// }

if (pathname === '/_internal/metric') {
const metric = await EdgeRuntime.getRuntimeMetrics();
return Response.json(metric);
Expand Down

0 comments on commit 1c19701

Please sign in to comment.