Skip to content

Commit

Permalink
Move caching logic to inside execution
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Cameron <[email protected]>
  • Loading branch information
nrc committed Jan 28, 2025
1 parent e265e4a commit 1554b50
Show file tree
Hide file tree
Showing 26 changed files with 304 additions and 427 deletions.
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ fn generate_code_block_test(fn_name: &str, code_block: &str, index: usize) -> pr
context_type: crate::execution::ContextType::Mock,
};

if let Err(e) = ctx.run(program.into(), &mut crate::ExecState::new(&ctx.settings)).await {
if let Err(e) = ctx.run(&program, &mut crate::ExecState::new(&ctx.settings)).await {
return Err(miette::Report::new(crate::errors::Report {
error: e,
filename: format!("{}{}", #fn_name, #index),
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/args_with_lifetime.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test_examples_someFn {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/args_with_refs.gen
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test_examples_someFn {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/array.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_show {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down Expand Up @@ -73,7 +73,7 @@ mod test_examples_show {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/box.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_show {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/doc_comment_with_code.gen
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod test_examples_my_func {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down Expand Up @@ -74,7 +74,7 @@ mod test_examples_my_func {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/lineTo.gen
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod test_examples_line_to {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down Expand Up @@ -74,7 +74,7 @@ mod test_examples_line_to {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-lib/derive-docs/tests/min.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_min {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down Expand Up @@ -73,7 +73,7 @@ mod test_examples_min {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/option.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_show {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/option_input_format.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_import {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/return_vec_box_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_import {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/return_vec_sketch.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_import {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/derive-docs/tests/show.gen
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod test_examples_show {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod test_examples_some_function {
context_type: crate::execution::ContextType::Mock,
};
if let Err(e) = ctx
.run(program.into(), &mut crate::ExecState::new(&ctx.settings))
.run(&program, &mut crate::ExecState::new(&ctx.settings))
.await
{
return Err(miette::Report::new(crate::errors::Report {
Expand Down
7 changes: 5 additions & 2 deletions src/wasm-lib/kcl-test-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ async fn snapshot_endpoint(body: Bytes, ctxt: ExecutorContext) -> Response<Body>
// Let users know if the test is taking a long time.
let (done_tx, done_rx) = oneshot::channel::<()>();
let timer = time_until(done_rx);
let snapshot = match ctxt.execute_and_prepare_snapshot(program.into(), &mut exec_state).await {
Ok(sn) => sn,
if let Err(e) = ctxt.run(&program, &mut exec_state).await {
return kcl_err(e);
}
let snapshot = match ctxt.prepare_snapshot().await {
Ok(s) => s,

Check warning on line 183 in src/wasm-lib/kcl-test-server/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

src/wasm-lib/kcl-test-server/src/lib.rs#L179-L183

Added lines #L179 - L183 were not covered by tests
Err(e) => return kcl_err(e),
};
let _ = done_tx.send(());
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-lib/kcl-to-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub async fn kcl_to_engine_core(code: &str) -> Result<String> {
let ctx = ExecutorContext::new_forwarded_mock(Arc::new(Box::new(
crate::conn_mock_core::EngineConnection::new(ref_result).await?,
)));
ctx.run(program.into(), &mut ExecState::new(&ctx.settings)).await?;
ctx.run(&program, &mut ExecState::new(&ctx.settings)).await?;

let result = result.lock().expect("mutex lock").clone();
Ok(result)
Expand Down
Loading

0 comments on commit 1554b50

Please sign in to comment.