Fork me on GitHub
#testing
<
2020-12-26
>
simongray15:12:53

I want to construct one or more relatively expensive NLP pipelines and use them in all of my tests, located in different test namespaces. How do I best accomplish this?

vemv16:12:47

what does a NLP pipeline look like? e.g. invoking a discrete expensive function, or connecting to a database, or ...

simongray16:12:37

In this case it’s a processing function backed by a multi-gigabyte memory model.

simongray16:12:27

… and the model takes a little while to load. The function itself is relatively quick to run.

vemv16:12:28

what's the problem in sharing it across namespaces like any other helper defn? concurrency perhaps?

simongray16:12:45

The main problem is the cost of instantiating. The way I tend to write unit tests, I have a lot of namespaces. I was just wondering if there was a typical pattern for reusing a fixture in tests like this.

vemv16:12:47

The model could be instantiated in a single ns: (def the-model (delay (initialize-model))) arbitrary defns could use this var. Only the first consumer initializes it, with no possible race conditions (https://github.com/clojure/clojure/blob/0df3d8e2e27fb06fa53398754cac2be4878b12d1/src/jvm/clojure/lang/Delay.java#L35) Does that sound like a good start?

simongray16:12:05

yeah, that makes sense.

simongray16:12:08

thanks!

🙌 3