Skip to content

Latest commit

 

History

History
53 lines (33 loc) · 3.22 KB

testing-strategies.adoc

File metadata and controls

53 lines (33 loc) · 3.22 KB

Clojure GraalVM Testing Strategies

Your Clojure project likely has a suite of tests. Here we explore options for ensuring your tests also work against your code after it has been natively compiled with GraalVM.

Conditional Spawning

This strategy works well when developing a command line tool.

conditional spawning

Clojure project source is AOT compiled to classes then natively compiled to an executable with GraalVM. The executable, in this case, is the command line tool.

The test suite is setup with a flag to either test Clojure source in the JVM or against the executable. The suite is run from the JVM twice:

  • once with the flag selecting to test against Clojure sources in the JVM

  • a second time with the flag selecting to run each test against a spawn of the executable

Examples of this technique can be found in clj-kondo and jet.

Test Compilation

This strategy could be considered when developing a Clojure library and wanting to make efforts to ensure it also works when natively compiled with GraalVM.

In this scenario you run your Clojure tests as normal but complement them with another run from a test runner executable created by GraalVM.

test compilation

The test runner could be written by hand or automatically generated. It explicitly requires all test namespaces, this way they will be automatically included during AOT compilation and hence into the test runner executable.

An example of the test compilation technique can be found in rewrite-clj. It is currently running successfully within the RAM constraints of GitHub Actions on macOS, Windows and Ubuntu.

A note from the author:

I spent a long while trying to get this running within the RAM constraints of free tier CI. Only after I enabled Clojure direct linking did Graal’s native-image RAM consumption shrink to work under GitHub Actions.

Test Interpretation

Although it offers no guarantees of consuming significantly less RAM, this strategy might be employed when you’ve exhausted every other avenue in natively compiling your tests within your imposed RAM constraints.

This technique may also be interesting if you want to ensure your library works as expected when exposed via SCI, the Small Clojure Interpreter.

Here your library, and any necessary supporting test libraries, are compiled with GraalVM and your tests are interpreted via SCI.

tests sci interpreted

Some more details can be found over at lread/sci-test. Be warned, sci-test is currently rewrite-cljc specific and should only serve as an example. Rewrite-cljc’s usage of this technique is available for study.