Skip to content

Conversation

@Carbonhell
Copy link

@Carbonhell Carbonhell commented Nov 9, 2025

Closes #401 .

This PR adds a few basic unit tests with Viceroy, a local runner for Fastly compute functions. There are a few functions I couldn't test:

  • set_ttl: there's no way to retrieve the TTL set on a Request struct, and the function itself is trivial;
  • send_request_to_s3: this function sends a HTTP request to the backend, and Viceroy does not allow intercepting them (see related issue). This also prevents implementing a test for handle_request. out of scope for this PR (needs to be tested with an integration test due to wasm)

While working on this, I noticed the build target was still set to wasm32-wasi (see here), which was breaking builds due to the target not being found - I've renamed it accordingly.
Also, I couldn't build the function either with the latest version of Rust (1.91) due to an ongoing incident with Fastly. I've pinned the version to 1.90 to allow builds, again. The incident was resolved, so I reverted the toolchain to stable.

The tests have been integrated in the CI as part of the "Rust projects" job, although this step takes slightly less than 6 minutes due to the installation of Viceroy, mostly. If that's too much time, I can look into caching, or we can split it to only download those tools and execute the tests when files change in the compute-static directory with dorny/paths-filter.

@Carbonhell Carbonhell force-pushed the tests-compute-static branch 2 times, most recently from 777d322 to 3b16d8b Compare November 10, 2025 22:43
@Carbonhell Carbonhell marked this pull request as ready for review November 10, 2025 22:54
Copy link

@amustaque97 amustaque97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

#!/bin/bash

# Start the Python HTTP server in the background, which will act as primary host for requests sent from Rust tests
python3 scripts/test_http_server.py &
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "real" way to write integration tests is actually another one, using viceroy-lib, directly, running the WASM binary. It's a little more complex, needs a non-wasm subcrate for the binary, bun I once made it work for a project then you could just use mockito to generate a test case specific mock-server. And it's a "real" integration test.

My proposal for this PR would be:
Keep it simple and just for unit-tests. It's already super helpful to be able to write normal unit-tests, without a real server. This small python server has only limited value for testing the many edge cases you want to test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I consider this implementation with the Python HTTP server hacky. I initially implemented it as I would've preferred to add coverage for the send_request_to_s3 function, as it's the common case handled by this compute function.
I didn't think of using viceroy-lib directly, that seems definitely cleaner. I just saw it's also mentioned in Viceroy's README as the suggested way to run integration tests. Considering the need for a subcrate for this kind of test, I also think it might be worth considering whether this is actually needed, and if so having a separate PR - I'll let the maintainers evaluate whether they'd appreciate this or if it's overkill for now.

@Carbonhell Carbonhell force-pushed the tests-compute-static branch from 6fbdfb0 to 360f2ce Compare December 4, 2025 22:19
fix: remame compute-static build target to wasip1
fix: pin toolchain to 1.90 due to https://www.fastlystatus.com/incident/378001
tweak: handle version-downloads URL path with/without trailing slash in the same way without permanent redirects
refactor: move request/response log collection to log_line to facilitate testing
…2e tests to test the whole flow in a simple case
tests(compute-static): add specific test for http method filter function
ci(compute-static): install cargo-nextest and viceroy via taiki-e/install-action
chore(compute-static): revert toolchain back to stable since fastly compute now works again on Rust 1.91.1
@Carbonhell Carbonhell force-pushed the tests-compute-static branch from 8df58f9 to 0c4e8d8 Compare December 4, 2025 22:22
@Carbonhell
Copy link
Author

I've reverted the toolchain to stable since the incident with Fastly was resolved, and I've removed the test using the background Python server. Let me know if the existing tests are enough or if there's any other case that I can add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write unit tests for static.crates.io function

3 participants