Skip to content

Commit 838ae8a

Browse files
committed
test(kernel): cover file store backend
1 parent c6c4862 commit 838ae8a

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

apps/es_kernel/test/es_kernel_store_tests.erl

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
-define(ETS_STORE_CONTEXT, {es_store_ets, es_store_ets}).
66
-define(MNESIA_STORE_CONTEXT, {es_store_mnesia, es_store_mnesia}).
7+
-define(FILE_STORE_CONTEXT, {es_store_file, es_store_file}).
78
-define(STREAM_A, {user, <<"account-A">>}).
89
-define(STREAM_B, {user, <<"account-B">>}).
910

1011
suite_test_() ->
11-
Stores = [?MNESIA_STORE_CONTEXT, ?ETS_STORE_CONTEXT],
12+
Stores = [?MNESIA_STORE_CONTEXT, ?ETS_STORE_CONTEXT, ?FILE_STORE_CONTEXT],
1213
BaseTests =
1314
[
1415
{"persist_single_event", fun persist_single_event/1},
@@ -35,10 +36,19 @@ suite_test_() ->
3536

3637
setup() ->
3738
mnesia:start(),
38-
ok.
39-
40-
teardown(_) ->
39+
RootDir = filename:join([
40+
"_build",
41+
"test",
42+
"es_store_file",
43+
integer_to_list(erlang:unique_integer([positive]))
44+
]),
45+
application:set_env(es_store_file, root_dir, RootDir),
46+
RootDir.
47+
48+
teardown(RootDir) ->
4149
mnesia:stop(),
50+
application:unset_env(es_store_file, root_dir),
51+
_ = file:del_dir_r(RootDir),
4252
ok.
4353

4454
%%% Helper functions
@@ -479,6 +489,20 @@ snapshot_save_error(?MNESIA_STORE_CONTEXT = Store) ->
479489
%% Normal save should still return ok
480490
?assertMatch(ok, es_kernel_store:store(Store, Snapshot)),
481491

492+
?assertEqual(ok, stop_store(Store));
493+
snapshot_save_error(?FILE_STORE_CONTEXT = Store) ->
494+
%% For the file store, stop/0 is intentionally a no-op. Verify the
495+
%% snapshot write path remains successful for this backend.
496+
?assertMatch(ok, start_store(Store)),
497+
498+
Timestamp = erlang:system_time(),
499+
State = #{balance => 100},
500+
Sequence = 5,
501+
Domain = user,
502+
503+
Snapshot = es_kernel_store:new_snapshot(Domain, ?STREAM_A, Sequence, Timestamp, State),
504+
?assertMatch(ok, es_kernel_store:store(Store, Snapshot)),
505+
482506
?assertEqual(ok, stop_store(Store)).
483507

484508
store_label({EventStore, SnapshotStore}) ->

0 commit comments

Comments
 (0)