fastly / Viceroy

Viceroy provides local testing for developers working with Compute.
https://fastly.dev/learning/compute/testing/#running-a-local-testing-server
Apache License 2.0
148 stars 34 forks source link

📘 add examples to `viceroy-lib` documentation #149

Open cratelyn opened 2 years ago

cratelyn commented 2 years ago

it would be nice if we provided some usage examples for viceroy_lib, to help people intending to use this library directly in their own testing infrastructure outside of the Fastly CLI.

i would particularly like to see examples showing how to start a service, and how to do this inside of a #[tokio::test] test case.

GeeWee commented 2 years ago

Yes I would absolutely love this as well - currently it's very hard to figure out how to make it work.

GeeWee commented 2 years ago

Some findings I've had to learn by myself.

You'll get very unhelpful errors like this when not running multithreaded:

thread 'test_cases::tests::foo::case_13' panicked at 'guest worker finished without panicking: JoinError::Panic(Id(13), ...)', /Users/gustavwengel/.cargo/registry/src/github.com-1ecc6299db9ec823/viceroy-lib-0.2.15/src/execute.rs:201:18
stack backtrace:

This has been several hours of trial and error, and I think if it was documented better, this would be much more usable.

caiges commented 1 year ago

@GeeWee Do you have your tests in a different Cargo project with either the default host target or some other NON wasm32-wasi target? It looks like viceroy depends on hyper which isn't compatible with a wasm32-wasi target so having our tests live in the same codebase seems problematic if they're sharing the same .cargo/config. Feeling out for a good testing pattern.

GeeWee commented 1 year ago

I have them inside a different crate that does not directly depend on the "main" API package, but which does expect it's built before running.

( I also have not set wasm32-wasi target in my .cargo/config - fastly compute serve & build works fine without it)