@@ -14,6 +14,50 @@ defmodule Cachex.WarmerTest do
14
14
assert Cachex . get! ( cache , 1 ) == 1
15
15
end
16
16
17
+ test "warmers with long running tasks" do
18
+ # create a test warmer to pass to the cache
19
+ TestUtils . create_warmer ( :long_running_warmer , fn _ ->
20
+ # exceed default timeout of `5000`
21
+ Process . sleep ( 5001 )
22
+ { :ok , [ { 1 , 1 } ] }
23
+ end )
24
+
25
+ # create a cache instance with a warmer
26
+ cache =
27
+ TestUtils . create_cache ( warmers: [ warmer ( module: :long_running_warmer ) ] )
28
+
29
+ # check that the key was warmed
30
+ assert Cachex . get! ( cache , 1 ) == 1
31
+ end
32
+
33
+ test "warmers with long running async tasks" do
34
+ # create a test warmer to pass to the cache
35
+ TestUtils . create_warmer ( :long_running_async_warmer , fn _ ->
36
+ { :ok ,
37
+ [ 1 , 2 ]
38
+ |> Task . async_stream (
39
+ fn num ->
40
+ # exceed default timeout of `5000`
41
+ Process . sleep ( 5001 )
42
+ { num , num }
43
+ end ,
44
+ timeout: :infinity
45
+ )
46
+ |> Stream . map ( fn { :ok , result } -> result end )
47
+ |> Enum . to_list ( ) }
48
+ end )
49
+
50
+ # create a cache instance with a warmer
51
+ cache =
52
+ TestUtils . create_cache (
53
+ warmers: [ warmer ( module: :long_running_async_warmer ) ]
54
+ )
55
+
56
+ # check that the keys were warmed
57
+ assert Cachex . get! ( cache , 1 ) == 1
58
+ assert Cachex . get! ( cache , 2 ) == 2
59
+ end
60
+
17
61
test "warmers which set values with options" do
18
62
# create a test warmer to pass to the cache
19
63
TestUtils . create_warmer ( :options_warmer , fn _ ->
0 commit comments