Repository navigation
test(nif): run the compiled NIF inside the BEAM #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
44573c0
test(nif): run the compiled NIF inside the BEAM
claude ed2d36e
ci(nif): build the NIF with --locked
claude 1e3c294
ci(nif): cache Cargo registry and build output in the NIF job
claude a86b40c
Merge branch 'main' into claude/peaceful-davinci-bra1b6-nif-tests
hyperpolymath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
elixir-orchestration/test/verisim/nif_bridge_loaded_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| defmodule VeriSim.NifBridgeLoadedTest do | ||
| @moduledoc """ | ||
| Exercises the compiled Rust NIF (`rust-core/verisim-nif`), not the | ||
| pure-Elixir fallback. | ||
|
|
||
| Every operation is still a scaffold, and the property that matters is that | ||
| each one fails loudly. An earlier NIF returned canned success (`delete_octad` | ||
| replied "deleted" having deleted nothing), which was silent data loss. | ||
|
|
||
| The fallback stubs answer `{:error, :nif_not_loaded}`; the real library | ||
| answers `{:error, :not_implemented}`. Asserting the exact atom therefore | ||
| proves the compiled NIF was loaded and answered. | ||
|
|
||
| Tagged `:nif`: runs only when the library is in `priv/native/` | ||
| (see `test_helper.exs`). | ||
| """ | ||
| use ExUnit.Case, async: true | ||
|
|
||
| alias VeriSim.{NifBridge, Transport} | ||
|
|
||
| @moduletag :nif | ||
|
|
||
| @operations [ | ||
| create_octad: [~s({"document":{"title":"t","body":"b"}})], | ||
| get_octad: ["e-1"], | ||
| delete_octad: ["e-1"], | ||
| search_text: ["q", 10], | ||
| search_vector: ["[0.1,0.2,0.3]", 5], | ||
| list_octads: [10, 0], | ||
| get_drift_score: ["e-1"], | ||
| trigger_normalise: ["e-1"] | ||
| ] | ||
|
|
||
| setup_all do | ||
| nif_path = Path.join(:code.priv_dir(:verisim), "native/libverisim_nif.so") | ||
| assert File.exists?(nif_path), "built NIF missing at #{nif_path}" | ||
| :ok | ||
| end | ||
|
|
||
| for {fun, args} <- @operations do | ||
| test "#{fun} is answered by the compiled NIF and fails loudly" do | ||
| assert {:error, :not_implemented} = | ||
| apply(NifBridge, unquote(fun), unquote(Macro.escape(args))) | ||
| end | ||
| end | ||
|
|
||
| test "the loaded NIF is not reported as operational" do | ||
| # loaded? is true only for a success result, which no operation returns. | ||
| refute NifBridge.loaded?() | ||
| end | ||
|
|
||
| test "auto transport keeps using HTTP while the NIF is non-operational" do | ||
| previous = System.get_env("VERISIM_TRANSPORT") | ||
| System.put_env("VERISIM_TRANSPORT", "auto") | ||
| on_exit(fn -> restore_env("VERISIM_TRANSPORT", previous) end) | ||
| refute Transport.use_nif?() | ||
| end | ||
|
|
||
| defp restore_env(key, nil), do: System.delete_env(key) | ||
| defp restore_env(key, value), do: System.put_env(key, value) | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.